SpringBoot项目的jar包瘦身计划
1:添加maven-dependency-plugin插件用于将引用的jar包拷贝到指定的路径,便于后续tomcat启动指定依赖包路径
<!--拷贝依赖到jar外面的lib目录--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--指定的依赖路径--> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin>
2:编译不打jar包的pom
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--以下configuration内的代码是不把jar包打进去,项目直接与jar包分离--> <configuration> <layout>ZIP</layout> <includes> <include> <groupId>nothing</groupId> <artifactId>nothing</artifactId> </include> <include> <groupId>你项目的groupId</groupId>
<artifactId>你项目的artifactId</artifactId>
</include>
</includes>
</configuration>
</plugin>
3:然后在启动项目时指定jar包路径-Dloader.path="../lib",这样就可以达到瘦身效果了
java -Dloader.path="D:develop/shared/lib" -jar 你的jar包名字.jar