前言:
SpringBoot 部署起来虽然简单,如果服务器部署在公司内网,速度还行,但是如果部署在公网(阿里云等云服务器上),部署起来实在头疼:编译出来的 Jar 包很大,如果工程引入了许多开源组件(SpringCloud 等),那就更大了。
这个时候如果想要对线上运行工程有一些微调,则非常痛苦
1.使用WinRAR
等解压工具解压之后可以得到lib文件,里面放着jar包
./lib/ 里面放jar包
./application-prod.properties 里面放配置文件
2.maven使用如下配置可以不引入lib,打包得到瘦身后的jar
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
<executable>true</executable>
<!--指定入口类-->
<mainClass>com.Application</mainClass>
<layout>ZIP</layout>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
3.运行
nohup java -Dloader.path=./lib/ -jar [包名].jar --spring.config.location=./application-prod.properties &
参考:
1.https://blog.csdn.net/qq_40793275/article/details/109147864?spm=1001.2014.3001.5501
2.https://cloud.tencent.com/developer/article/1768660
3.https://blog.csdn.net/m0_61193461/article/details/121717053