欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SpringBoot/SpringCloud maven分离打包

程序员文章站 2024-03-22 18:59:58
...

SpringBoot/SpringCloud maven分离打包

目的:把微服务的jar包尽量变得足够小,公共不变jar包进行提取放到特定文件夹内,然后启动jar包的时候进行指定lib文件目录地址即可。

以下是我的maven配置:

	<build>
		<plugins>
			<plugin>
				<!--打包时去除第三方依赖-->
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<layout>ZIP</layout>
					<includes>
					    <!--此处可以指定包含jar包-->
						<include>
							<groupId>non-exists</groupId>
							<artifactId>non-exists</artifactId>
						</include>
					</includes>
				</configuration>
			</plugin>
			<!--拷贝第三方依赖文件到指定目录-->
			<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>
							<!--target/lib是依赖jar包的输出目录-->
							<outputDirectory>D:/workspace/demo-service/target/lib</outputDirectory>
							<!--<excludeTransitive>false</excludeTransitive>
							<stripVersion>false</stripVersion>
							<includeScope>compile</includeScope>-->
						</configuration>
					</execution>
				</executions>
				<configuration>
					<!-- 本地Jar包不进行分离,不输出到outputDirectory -->
					<excludeGroupIds>com.demo.service</excludeGroupIds>
				</configuration>
			</plugin>
		</plugins>
		<finalName>${project.artifactId}</finalName>
	</build>
  • 启动命令:
    java -jar -Dloader.path=D:/workspace/demo-service/target/lib demo-service-demo1.jar