1、mvn 打包猿妈,將lib吹菱、jar、conf分開
spring-boot-maven-plugin:打包成可執(zhí)行的文件
maven-jar-plugin:負(fù)責(zé)將應(yīng)用程序打包成可執(zhí)行的jar文件
maven-assembly-plugin:負(fù)責(zé)將整個項目按照自定義的目錄結(jié)構(gòu)打成最終的壓縮包彭则,方便實際部署
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.adtec.rdc.moia.dispatch.DispatchWebSpringBootApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<descriptors>
<descriptor>src/main/resources/config/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 打包發(fā)布時鳍刷,跳過單元測試 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
config/package.xml
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id>
<!-- 打包后的文件格式,可以是zip,tar,tar.gz,tar.bz2,jar,war,dir -->
<formats>
<format>dir</format>
</formats>
<!-- 壓縮包下是否生成和項目名相同的根目錄 -->
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<!-- 不使用項目的artifact,第三方j(luò)ar不要解壓俯抖,打包進(jìn)zip文件的lib目錄 -->
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<!-- 說明文件输瓜,打包進(jìn)zip文件的根目錄 -->
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory></outputDirectory>
<fileMode>0644</fileMode>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<!-- 配置文件,打包進(jìn)zip文件的conf目錄 -->
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode>
<includes>
<include>*.properties</include>
<include>*.xml</include>
<include>*.yml</include>
<include>change.log</include>
</includes>
</fileSet>
<!-- 啟動腳本,打包進(jìn)zip文件的bin目錄 -->
<fileSet>
<directory>${project.basedir}/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
<includes>
<include>*.bat</include>
<include>*.sh</include>
</includes>
</fileSet>
<!-- 編譯出來的jar文件尤揣,打包進(jìn)zip文件根目錄 -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
打包結(jié)果
2搔啊、java -cp 運(yùn)行時加載jar包。
https://blog.51cto.com/u_330478/5020251
3北戏、nohup
nohup ${JAVA} ${JAVA_OPT} -cp $classpath ${MAIN_CLASS} >start.log 2>&1 &
nohup ${JAVA} ${JAVA_OPT} -cp $classpath ${MAIN_CLASS} >/dev/null 2>nohup.out &