一、springboot自带的fatjar
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
idea添加的springboot项目的时候,自动带有上面的打包方式,将依赖的jar也打到一起,俗称:fatjar,启动方式为java -jar jar包名称,一般使用在小型项目上。
二、maven-dependency-plugin打包
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.hikvision.starfinshpassengers.StarfishPassengersApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
三、maven-assembly-plugin打包
assembly.xml
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>build</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory>\config</outputDirectory>
<includes>
<include>application.properties</include>
<include>startupConfig.xml</include>
<include>logback.xml</include>
<include>cas-client.properties</include>
<include>linux-x86-64</include>
</includes>
<directoryMode>0755</directoryMode>
<fileMode>0644</fileMode>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/assembly/temp</directory>
<outputDirectory>\temp</outputDirectory>
<directoryMode>0755</directoryMode>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/assembly/logs</directory>
<outputDirectory>\logs</outputDirectory>
<directoryMode>0755</directoryMode>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/bin</directory>
<outputDirectory>\bin</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<directoryMode>0755</directoryMode>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>\lib</outputDirectory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>\lib</outputDirectory>
<scope>runtime</scope>
<directoryMode>0755</directoryMode>
</dependencySet>
</dependencySets>
</assembly>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<!-- start模块在jar包中排除工程配置文件 -->
<!-- <excludes>-->
<!-- <exclude>/*.properties</exclude>-->
<!-- <exclude>logback.xml</exclude>-->
<!-- <exclude>startupConfig.xml</exclude>-->
<!-- </excludes>-->
</configuration>
</plugin>
<!-- 设置源文件编码方式 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- 打包source文件为jar文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>starfinshpassengers</finalName>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>../../output/</outputDirectory>
<archive>
<manifest>
<mainClass>com.hikvision.starfinshpassengers.StarfishPassengersApplication</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
打包之后,通过Jvsc进行启动,启动命令
./Jsvc -home /opt/opsmgr/web/components/jre18linux64.1 -cwd /home/hik/starfinshpassengers/config -Dloader.main=com.hikvision.starfinshpassengers.StarfishPassengersApplication -outfile /home/hik/starfinshpassengers/logs/debug.log -errfile /home/hik/starfinshpassengers/logs/error.log -Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=58889 -cp /opt/opsmgr/web/components/jre18linux64.1/jre/lib/dt.jar:/opt/opsmgr/web/components/jre18linux64.1/jre/lib/tools.jar:/home/hik/starfinshpassengers/lib/* com.hikvision.ga.common.JsvcLauncher