maven spring boot项目精简打包
由于生产项目测试需要频繁打包,所以需要单独导出项目依赖的lib,每次修改只针对项目进行打包操作
- maven的文件配置
....
<!-- 打包方式改为jar -->
<packaging>jar</packaging>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
<!-- 指定main的入口类 -->
<mainClass>com.bayss.simple.DemoApplication</mainClass>
<layout>ZIP</layout>
<!-- 排除依赖包 -->
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
- 导出项目依赖
-DoutputDirectory指定项目路径
-DincludeScope设置依赖级别,通常使用compile级别
mvn dependency:copy-dependencies -DoutputDirectory=target/lib -DincludeScope=compile
3. 执行运行jar
java -Dloader.path=lib -jar demo-0.0.1-SNAPSHOT.jar