spring boot 打包和部署

来源:互联网 发布:淘宝童装促销文案 编辑:程序博客网 时间:2024/05/17 03:59

这两天项目刚刚写完准备测试,项目是用Springboot搭建的,一个project和三个module,分别是API(用来其他系统的调用,包括前端)、service(内含service层、dao层和mapper以及mybatis的xml文件)和job(任务调度的module),其中API依赖service和job。在父类和API中添加如下的启动项,而在父类中不用处理,因为这是在API中进行的打包操作:

  <build>    <plugins>      <!--提供mvn命令直接运行springboot-->      <plugin>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-maven-plugin</artifactId>      </plugin>    </plugins>    <resources>      <resource>        <directory>src/main/resources</directory>        <filtering>true</filtering>        <excludes>          <exclude>application.properties</exclude>          <exclude>application-dev.properties</exclude>          <exclude>application-online.properties</exclude>          <exclude>application-test.properties</exclude>          <exclude>logback-spring.xml</exclude>        </excludes>      </resource>      <resource>        <filtering>true</filtering>        <directory>src/main/resources</directory>        <includes>          <include>application.properties</include>          <include>application-${profileActive}.properties</include>          <include>logback-spring.xml</include>        </includes>      </resource>    </resources>  </build>

运行在idea的控制台运行mvn clean package Ptest这个mvn命令,打包test环境的配置文件,将项目打成jar包。

jar包打包完成后将jar包上传到Linux的系统坏境,写一个启动脚本,运行下边的脚本就可以将项目启动:

#!/bin/bashnohup java -jar yourapp.jar &echo Asset is already started!

&符号的意思是程序在后台运行,nohup是不挂断的运行命令,这样就可以保证程序运行的时候始终保持。需要注意的是,将脚本文件在文本中编辑后上传到Linux中后,运行时会出现以下这两个错误:

stop.sh: line 11: syntax error: unexpected end of file: command not found

这是由于格式不合符要求导致的,因此要设置格式,设置格式的命令如下:

vi start.sh:set fileformat=unix:wq

下边是stop.sh脚本:

#!/bin/bashPID=$(ps -ef | grep yourappp.jar | grep -v grep | awk '{ print $2 }')if [ -z "$PID" ]then    echo Asset is already stopped!else    echo kill $PID    kill $PIDecho Asset stopped!fi


1 0
原创粉丝点击