在使用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>
java -Dloader.path=libs包全路径 -jar open-deer.jar
java -Dloader.path=libs/ -jar open-deer.jar