springboot web项目打包成 jar包部署在服务器

springboot web项目打包成jar包部署在服务器

  • springboot web项目打包成jar包部署在服务器
    • pom.xml
    • Controller返回页面
    • 部署和运行jar包
    • 大功告成~~~

pom.xml

虽然官方并不推荐把网页放在webapp,但是我这边还是使用了webapp。


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>cn.com.testgroupId>
    <artifactId>testartifactId>
    <version>0.0.1-SNAPSHOTversion>
    
    <packaging>jarpackaging>

    <name>testname>
    <description>测试测试description>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>1.5.9.RELEASEversion>
        <relativePath/> 
    parent>

    <repositories>
        <repository>
            <id>alimavenid>
            <name>aliyun mavenname>
            <url>http://maven.aliyun.com/nexus/content/groups/public/url>
            <releases>
                <enabled>trueenabled>
                <updatePolicy>dailyupdatePolicy>
                <checksumPolicy>ignorechecksumPolicy>
            releases>
            <snapshots>
                <enabled>trueenabled>
                <updatePolicy>dailyupdatePolicy>
                <checksumPolicy>ignorechecksumPolicy>
            snapshots>
            <layout>defaultlayout>
        repository>
    repositories>

    <properties>
        
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
        
        <maven.compiler.encoding>UTF-8maven.compiler.encoding>
        <java.version>1.8java.version>
        <okhttp.version>3.9.1okhttp.version>
        <guava.version>23.5-jreguava.version>
        <fastjson.version>1.2.42fastjson.version>
        <druid.version>1.1.6druid.version>
        <informix.jdbc.version>4.10.JC7DEinformix.jdbc.version>
        <mybatis.version>1.3.1mybatis.version>
        <mybatis.pagehelper.version>1.2.3mybatis.pagehelper.version>
        <mybatis.base.version>1.2.1mybatis.base.version>
        <quartz.version>2.2.1quartz.version>
        <lombok.version>1.16.20lombok.version>
        <poi.version>3.10-FINALpoi.version>
        <commons-io.version>2.2commons-io.version>
    properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-jpaartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-securityartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-thymeleafartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>



        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>fastjsonartifactId>
            <version>${fastjson.version}version>
        dependency>

        
        <dependency>
            <groupId>com.squareup.okhttp3groupId>
            <artifactId>okhttpartifactId>
            <version>${okhttp.version}version>
        dependency>

        
        <dependency>
            <groupId>com.google.guavagroupId>
            <artifactId>guavaartifactId>
            <version>${guava.version}version>
        dependency>

        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druid-spring-boot-starterartifactId>
            <version>${druid.version}version>
        dependency>

        <dependency>
            <groupId>com.oraclegroupId>
            <artifactId>ojdbc6artifactId>
            <version>11.2.0.3.0version>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-tomcatartifactId>
            
        dependency>



        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-actuatorartifactId>
        dependency>



        
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <version>${lombok.version}version>
            <scope>providedscope>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>

        <dependency>
            <groupId>org.apache.commonsgroupId>
            <artifactId>commons-lang3artifactId>
            <version>3.4version>
        dependency>

        <dependency>
            <groupId>org.apache.poigroupId>
            <artifactId>poiartifactId>
            <version>${poi.version}version>
        dependency>
        <dependency>
            <groupId>commons-iogroupId>
            <artifactId>commons-ioartifactId>
            <version>${commons-io.version}version>
        dependency>
    dependencies>

    <build>
        
        <finalName>testfinalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>

        
        <resources>
            <resource>
                <directory>src/main/resourcesdirectory>
            resource>
            <resource>
                <directory>src/main/webappdirectory>
                <targetPath>META-INF/resourcestargetPath>
            resource>

        resources>
    build>


project>

Controller返回页面

这里需要注意,Controller返回页面页面时前面不要加/否则部署到服务器上thymeleaf会解析不出来

/**
     * 登录请求
     * @return
     */
    @RequestMapping("/login")
    public String login(){
        return "login";
    }

部署和运行jar包

常规的将jar包上传到服务器上面之后,就可以进行部署了
这里附上shell脚本,我这边指定了jdk为1.8

export JAVA_HOME=/home/jdk1.8.0_161
export JRE_HOME=/home/jdk1.8.0_161/jre
export PATH=$JAVA_HOME/bin:$PATH
ps -ef | grep 'test' | grep -v grep| awk '{print $2}' | xargs kill -9 
sleep 10;
java -jar /home/test/test.jar > /home/test/output.log 2>&1 &

shell指令的意义参考下文
shell指令的意义

大功告成~~~

撒花撒花撒花

你可能感兴趣的:(springboot)