spring-boot-maven-plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
这是我们最常见的springboot打包方法,但是使用spring-boot-maven-plugin打包是打成整包发布,依赖的jar与我们的代码包是放在一起发布的,更换部署是很麻烦的。而且你会发现,发布包的主类是Springboot封装之后的。
maven-jar-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<!-- 添加index则不从mainfest中读取classpath,而是从Index.list中读取 -->
<!-- <index>true</index> -->
<manifest>
<mainClass>cn.maritech.dss.DSS</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>../libs/</classpathPrefix>
</manifest>
<!--<manifestEntries>-->
<!--<Class-Path>../resources</Class-Path>-->
<!--</manifestEntries>-->
</archive>
<excludes>
<exclude>data/**</exclude>
<exclude>static/**</exclude>
<exclude>templates/**</exclude>
<exclude>*.txt</exclude>
<exclude>*.xml</exclude>
<exclude>*.properties</exclude>
</excludes>
</configuration>
</plugin>
这是目前是使用的打包方法。也就是maven jar打包方法,不同的是将前端资源也打包进去。方法比较老派,但是很好用。Spingboot的jar还是作为依赖库使用。结合maven-assembly-plugin形成部署态文件夹。
maven-assembly-plugin没有任何编译功能,这东西就是文件迁移、做文件夹用的。
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!--jar包名称-->
<finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
<executions>
<execution>
<id>full</id>
<!-- 绑定到package生命周期阶段上 -->
<phase>package</phase>
<goals>
<!-- 只运行一次 -->
<goal>single</goal>
</goals>
<configuration>
<!--描述文件路径-->
<descriptor>${basedir}/assembly/assembly.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
<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
http://maven.apache.org/ASSEMBLY/2.0.0 ">
<!--这个id会跟在打包文件后面,现还不清楚怎么取消-->
<id>release</id>
<formats>
<format>dir</format>
</formats>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>libs</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.basedir}\data</directory>
<outputDirectory>data</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}\src\main\resources</directory>
<outputDirectory>resources</outputDirectory>
<!--<includes>-->
<!--<include>*.xml</include>-->
<!--<include>*.properties</include>-->
<!--</includes>-->
</fileSet>
<fileSet>
<directory>${project.basedir}/wrapper</directory>
<outputDirectory>bin</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}/jre</directory>
<outputDirectory>jre</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
参考链接
http://www.cnblogs.com/gannalyo/p/9681567.html