在使用Springboot开发项目时,打包好的jar包是可以直接运行的,但是通常情况下,这个jar都会很大,因为它默认打包了所有的依赖jar包。此时,就可以通过maven-dependency-plugin插件将依赖包复制到独立的文件夹,在启动jar包的时候引用即可。
<build>
<finalName>iteachyou-cms</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>cn.xuexiluxian.open.admin.OpenDeerApplication</mainClass>
<layout>ZIP</layout>
<includes>
<include>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>open-deer</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<type>jar</type>
<includeTypes>jar</includeTypes>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
配置说明
cn.xuexiluxian.open.admin.OpenDeerApplication 用于指定该jar包启动时的主类(建议加上)
加上自己项目的groupId和artifactId即可
open-deer 值自定义
${project.build.directory}/libs 依赖包输出目录
其它写死
启用项目
java -Dloader.path=libs包全路径 -jar open-deer.jar
java -Dloader.path=libs/ -jar open-deer.jar