一、前提
由于gitlab的域名不可用,只能上传jar到服务器进行发布,但是springboot打包会将所依赖的jar包一并打包在程序的jar中,这样jar包体积比较大,上传就会变得很费时。通过网上查询的资料,将所依赖的jar包和程序jar包进行分开打包,如果需要上传只需要上传很小的程序jar包就可以了。
二、使用步骤
1.原本打包方式
代码如下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
这种打包方式是springboot提供的maven打包方式,会将依赖jar包打入到程序包中
这是sping提供的文档:https://docs.spring.io/spring-boot/docs/2.4.0/maven-plugin/reference/htmlsingle/,是没办法提供程序jar包中MANIFEST.MF指定Spring-Boot-Lib: BOOT-INF/lib/路径的。
2.解决办法
代码如下:
<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-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.promote.basic.PromoteBasicApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-lib</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
将maven的打包和springboot的一起结合使用。将所依赖jar包打包到同级目录下的lib文件夹下,同时将程序jar包中MANIFEST.MF中会添加Class-Path: 指定所需的依赖jar包。
使用mvn clean install重新打包项目
使用 java -jar 启动项目
总结
网上也找了很多资料,也试了很多方式,最后改成了这样,欢迎大佬指正问题。