- 在pom中新增插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
这两个插件一个是用来收集项目运行时需要的依赖到指定的目录,这里指定目录为target\lib
下。
还有一个就是SpringBoot提供的打包工具,只不过加入打包时不需要将依赖打进项目的配置参数而已。
-
指定mvn package 打包后,target目录下文件
- 运行项目时需要指定依赖的存放路径
nohup java -Dloader.path="./lib" -jar $JVM_OPS ${JAVA_BASE_SRC}/${PROJECT_JAR} &