maven打包SpringBoot项目部署,分离依赖jar包和静态资源

使用到多个插件,生成后结构
maven打包SpringBoot项目部署,分离依赖jar包和静态资源
pom中的build内容

<build>
		<defaultGoal>compile</defaultGoal>
		<plugins>
			<plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.5</version>
				<configuration>
					<!-- 在控制台打印执行日志 -->
					<verbose>true</verbose>
					<!-- 重复生成时会覆盖之前的文件 -->
					<overwrite>true</overwrite>
					<configurationFile>src/main/resources/mybatis-generator-config.xml</configurationFile>
				</configuration>
				<!-- 数据库连接选择8.0以上的,因为用的mysql8.0 -->
				<dependencies>
					<dependency>
						<groupId>mysql</groupId>
						<artifactId>mysql-connector-java</artifactId>
						<version>8.0.16</version>
					</dependency>
				</dependencies>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<!-- <mainClass>com.gdata.IotApp</mainClass> -->
							<addClasspath>true</addClasspath>
						</manifest>
						<!-- 指定配置文件目录,这样jar运行时会去找到同目录下的resources文件夹下查找 -->
						<manifestEntries>
							<Class-Path>./resources</Class-Path>
						</manifestEntries>
					</archive>
					<!-- 打包时忽略的文件(也就是不打进jar包里的文件) -->
					<excludes>
						<exclude>**/**.lib</exclude>
						<exclude>static/**</exclude>
						<exclude>templates/**</exclude>
						<exclude>*.*</exclude>
					</excludes>
				</configuration>
			</plugin>

			<!-- springboot repackage -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<!-- <mainClass>com.gdata.IotApp</mainClass> -->
					<layout>ZIP</layout>
					<addResources>true</addResources>
					<includes>
						<include>
							<groupId>non-exists</groupId>
							<artifactId>non-exists</artifactId>
						</include>
					</includes>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<!-- 分离lib -->
			<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>
							<!-- 依赖包输出目录 -->
							<outputDirectory>${project.build.directory}/lib</outputDirectory>
							<excludeTransitive>false</excludeTransitive>
							<stripVersion>false</stripVersion>
							<!-- 依赖包的作用域 -->
							<includeScope>runtime</includeScope>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<!-- 复制资源文件 -->
			<plugin>
				<artifactId>maven-resources-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-dependencies</id>
						<phase>package</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<!-- 资源文件输出目录 -->
							<outputDirectory>${project.build.directory}/resources</outputDirectory>
							<resources>
								<resource>
									<directory>src/main/resources</directory>
								</resource>
							</resources>
						</configuration>
					</execution>
					<execution>
						<id>copy-cert</id>
						<phase>package</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<!-- 资源文件输出目录 -->
							<outputDirectory>${project.build.directory}/cert</outputDirectory>
							<resources>
								<resource>
									<directory>cert</directory>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
		<resources>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.xml</include>
				</includes>
			</resource>
			<resource>
				<directory>src/main/resources</directory>
			</resource>
		</resources>
	</build>
上一篇:first-order-model学习笔记(二):运行参数


下一篇:maven 插件用于打不同环境的版本包