SpringBoot 项目瘦身部署

拷贝依赖到jar外面的lib目录

<build>
	<plugins>
		<!--  拷贝依赖到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>

执行maven-->install

jar包瘦身

<build>
	<plugins>
		<!--  jar包瘦身  -->
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
				<executable>true</executable>
				<mainClass>com.mobai.color.ColorApplication</mainClass>
				<layout>ZIP</layout>
				<!--  引入需要的包 -->
				<includes>
					<!--  只引入自己 -->
					<include>
						<groupId>${groupId}</groupId>
						<artifactId>${artifactId}</artifactId>
					</include>
					<!--  或都不引入 -->
					<!--<include>
						<groupId>nothing</groupId>
						<artifactId>nothing</artifactId>
					</include>-->
				</includes>
			</configuration>
			<executions>
				<execution>
					<goals>
						<goal>repackage</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

执行maven-->install

将项目的jar包上传到服务器中,以及lib文件夹也上传到服务器

将项目jar包与lib文件置于同一目录下,执行以下命令启动项目

java -Dloader.path=/home/power/lib -jar /home/power/XXX.jar

多个项目jar存放于同一目录并需启动时,重命名各个项目的lib文件夹名为:XXX_lib,执行以下命令启动项目

java -Dloader.path=/home/power/XXX_lib -jar /home/power/XXX.jar


标题:SpringBoot 项目瘦身部署
作者:Mune
地址:https://cnxiaobai.com/articles/2021/04/21/1619003560634.html

    评论
    0 评论
avatar

取消