一、maven添加如下配置
<build>
<resources>
<resource>
<!--resources下的所有配置文件 -->
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<!--根据profiles参数 导入测试或生产环境配置文件 -->
<directory>src/main/config/${profiles.activation}</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!--jar配置 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.2.RELEASE</version>
<configuration>
<mainClass>com.xxx.xxxx.ServerApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.xxx.xxxx.ServerApplication</mainClass>
<!--依赖前缀-->
<classpathPrefix>lib/</classpathPrefix>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Class-Path>resources/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>xxx-server</finalName>
</build>
assembly.xml文件配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3
http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>package</id>
<!--zip 压缩方式 -->
<formats>
<!--压缩文件的类型-->
<!--<format>zip</format>-->
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
二、启动脚本
#!/bin/bash
export JAVA_HOME=/usr/local/jdk1.8.0_161/
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=.:${JAVA_HOME}/bin:$PATH
nohup java -jar xxxxxxxxxxxxxxx.jar > /dev/null 2>&1 &
三、停止脚本
#!/bin/bash
PID=$(ps -ef | grep xxxxxxxxxxxxxxx.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo Application is already stopped
else
echo kill $PID
kill $PID
fi
四、脚本意思
普通启动,关闭当前窗口,程序关闭(不推荐使用)
java -jar xxxxxxxxxx.jar
后台启动命令
nohup java -jar xxx.jar > nohup.out 2>&1 &
后台启动命令将日志文件放到黑洞中
nohup java -jar xxxxxxxxx.jar > /dev/null 2>&1 &