官方文档http://maven.apache.org/plugins/maven-resources-plugin/index.html
它最常用的两个goal:
resources:resources 这是process-resources阶段的默认goal, 在不配置任何参数的情况下,将默认使用build.resources中的目录作为源路径,将build.outputDirectory作为目标路径(实际上是这目录下的classes).
resources:copy-resources 需要明确的指定源路径和目标路径.
示例如下
<build>
<outputDirectory>${project.basedir}/target</outputDirectory> <!-- 废代码,默认值就是个 -->
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory> <!-- 废代码, 默认值 -->
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution> <!--本示例显式地配置了process-resource阶段的插件配置-->
<id>default-resources</id> <!-- default-resources是process-resource阶段绑定的id,因此本配置将取代默认的配置 -->
<phase>validate</phase><!-- 默认操作原本是在process-resource阶段执行的,本示例将其更改到了validate阶段 -->
<goals>
<goal>resources</goal><!--废代码,default-resources的goal就是resource,如果这里的值更改为copy-resources, 则需要显示配置resource和outputDirectory, 并且导致资源拷贝操作被执行两次 -->
</goals>
<configuration>
<!-- 如果不配置,则使用build.resources作为源,build.outputDirectory作为目标, 如果明确进行了配置,build.resources将被忽略 -->
<!-- </br>
<outputDirectory>${project.basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<skip>false</skip> 如果配置为true,则本操作不被执行
-->
</configuration>
</execution>
<execution>
<id>copy2</id> <!--自定义的id,随便写 -->
<phase>compile</phase><!--在compile阶段执行-->
<goals>
<goal>copy-resources</goal><!--这个goal需要明确的配置-->
</goals>
<configuration>
<outputDirectory>${project.basedir}/target/conf3</outputDirectory>
<resources>
<resource>
<directory>src/main/resources3</directory>
<filtering>true</filtering> <!--开启资源文件插值操作-->
<includes><!--包含directory下的所有的properties, 包括子目录-->
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
filter,见maven pom进阶教程 - properties、filter