项目pom.xml文件中添加下面的配置:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<layout>ZIP</layout>
<!--这里是填写需要包含进去的jar,
必须项目中的某些模块,会经常变动,那么就应该将其坐标写进来
如果没有则nothing ,表示不打包依赖 -->
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
</plugin>
<!--拷贝依赖到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>
</plugins>
</build>
2.启动加上
java -Dloader.path=./lib -jar
启动时 还是报notclass
原因是spring-boot-maven-plugin 没有配置<layout>ZIP</layout>
使用 spring-boot-maven-plugin 插件,layout加载方式改为 ZIP 模式可以实现。(因为该插件是在maven-jar-plugin 插件之后执行)
所得jar包中: MANIFEST.MF 文件内容如下,请注意 Main-Class是PropertiesLauncher
,这个是pom中 spring-boot-maven-plugin 插件配置 <layout>ZIP</layout>
的结果。
Manifest-Version: 1.0
Implementation-Title: APP启动配置
Implementation-Version: 1.0.0.0
Start-Class: com.bdsoft.BDPWebApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Build-Jdk-Spec: 1.8
Spring-Boot-Version: 2.2.7.RELEASE
Created-By: Maven Jar Plugin 3.2.0
Main-Class: org.springframework.boot.loader.PropertiesLauncher