pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<!--用于处理项目的依赖插件-->
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<!--复制依赖-->
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 依赖包输出目录,将来不打进jar包里 -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<!--下面两项在copy-dependencies时需要设置-->
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<!--运行时-->
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<!--资源管理插件-->
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<!--源文件目录-->
<directory>src/main/resources</directory>
</resource>
</resources>
<!--输出的资源目录-->
<outputDirectory>${project.build.directory}/resources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<!--打包时需要排除的文件-->
<exclude>static/**</exclude>
<exclude>templates/**</exclude>
<exclude>*.yaml</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--必须使用zip的方式-->
<layout>ZIP</layout>
<includes>
<include>
<!--这里随便设置一个名字,在打包时就不会将依赖打包进来-->
<groupId>non-exists</groupId>
<artifactId>non-exists</artifactId>
</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
启动命令如下:
java -jar -Dloader.path=.,resources,lib *.jar