Maven项目的两种打包方式-spring-boot-mavne-plugin/maven-jar-plugin
- 1. 前言
- Maven的两种打包方式
- 2. 流程图
- 3. spring-boor-maven-plugin打包
- 4. maven-jar-plugin/maven-dependency-plugin打包
1. 前言
Maven的两种打包方式
- spring-boot-maven-plugin
springboot默认打包方式方便快捷,但是打出的jar包太大,一些公共的依赖每个jar都要有一份. - maven-jar-plugin/maven-dependency-plugin
打包公共依赖和代码可以放开打包,不同jar包可以共用一个dependency.jar,使打包文件变小,需要额外引入打包依赖
参考文档
- spring-boot-maven-plugin文档: spring-boot-maven-plugin
- maven-jar-plugin文档: maven-jar-plugin
- maven-dependency-plugin文档: maven-dependency-plugin
2. 流程图
3. spring-boor-maven-plugin打包
pom.xlm增加
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- true 不将依赖进行打包 false 打包依赖 -->
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
4. maven-jar-plugin/maven-dependency-plugin打包
pom.xml增加
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<useUniqueVersions>true</useUniqueVersions>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
<!-- main 所在路径 -->
<mainClass>com.zlm.Application</mainClass>
</manifest>
</archive>
<outputDirectory>../outputDirectory</outputDirectory>
</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>../outputDirectory/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>