plugin 配置
<build>
<finalName>${project.artifactId}</finalName>
<defaultGoal>compile</defaultGoal>
<resources>
<!--打包進XML等文件,排除java及版本控制文件 -->
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/.git/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.yml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- 複製資源文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<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}/config</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<!-- 指定配置文件目錄,這樣jar運行時會去找到同目錄下的resources文件夾下查找 -->
<manifestEntries>
<Class-Path>resources/</Class-Path>
</manifestEntries>
</archive>
<!-- 打包時忽略的文件(也就是不打進jar包裏的文件)-->
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/.git/*</exclude>
<exclude>**/*.yml</exclude>
</excludes>
</configuration>
</plugin>
<!-- 拷貝項目所有依賴jar文件到構建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}/libs</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<silent>true</silent>
<!-- 依賴包的作用域 -->
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<!-- Spring Boot模塊jar構建 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
<includes>
<include>
<groupId>non-exists</groupId>
<artifactId>non-exists</artifactId>
</include>
</includes>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>