Maven配置模板:资源分离打包
完整Demo,直接复制build即可食用
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>auto-test</artifactId>
<groupId>com.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>auto-perf-agent</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>auto-test-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<!-- 根据情况,排除文件配置 -->
<!-- <excludes> -->
<!-- <exclude>*.**</exclude> -->
<!-- <exclude>*/**.xml</exclude> -->
<!-- </excludes> -->
<!-- 包含文件配置,配置只打包 com 文件夹 -->
<includes>
<include>
**/com/**
</include>
</includes>
<archive>
<manifest>
<!-- 配置加入依赖包:MANIFEST.MF -->
<addClasspath>true</addClasspath>
<!-- 前缀,写在MANIFEST.MF文件中 -->
<classpathPrefix>lib/</classpathPrefix>
<useUniqueVersions>false</useUniqueVersions>
<!-- Spring Boot 启动类(自行修改) -->
<mainClass>com.test.PerfTestAgentApplication</mainClass>
</manifest>
<manifestEntries>
<!-- 外部资源路径加入 MANIFEST.MF 的 Class-Path -->
<!-- 写多个 Class-Path 貌似只有最后一个才能生效,可以写在同一行,空格隔开 -->
<Class-Path>resources/</Class-Path>
</manifestEntries>
</archive>
<!-- jar 输出目录 -->
<outputDirectory>${project.build.directory}/pkgs/</outputDirectory>
</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>
<!-- 依赖包 输出目录 -->
<outputDirectory>${project.build.directory}/pkgs/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<!-- 复制资源到resources目录 -->
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.sh</exclude>
</excludes>
</resource>
</resources>
<!-- 资源文件 输出目录 -->
<outputDirectory>${project.build.directory}/pkgs/resources</outputDirectory>
</configuration>
</execution>
<!-- 复制shell脚本到根目录 -->
<execution>
<id>copy-resources-shell</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.sh</include>
</includes>
</resource>
</resources>
<!-- 资源文件 输出目录 -->
<outputDirectory>${project.build.directory}/pkgs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>