http://www.cnblogs.com/pixy/p/4798089.html
http://www.360doc.com/content/15/0123/10/20466010_443036304.shtml
maven的resources插件职责是将项目的资源文件拷贝到目标目录。maven将资源划分为两类:main resources 和 test resources。因此有如下三个相应的goal:
1. resources:resources
- command: mvn resources:resources
- bound by default to the process-resources life-cycle phase
- copies the resources for the main source code to the main output directory
- the resources for your main source code, is by default specified by the
<resources>
element (project.build.resources
, 默认是src/main/resources
) - the main build output directory, is by default specified by the
project.build.outputDirectory
element
2. resources:testResources
- command: mvn resources:testResources
- bound by default to the process-test-resources life-cycle phase
- copies the resources for the test source code to the test output directory
- the resources for your test source code, is by default specified by the
<testResources>
(project.build.testResources
) element - the test build output directory, is by default specified by the
project.build.testOutputDirectory
element
3. resources:copy-resources
- command: mvn resources:copy-resources
- requires that you configure the phase to be bound to (specified as part of the plugin configuration)
- copies resources to an output directory
- Rather than using the or elements or their defaults, this uses a element that is specified as part of the plugin configuration
- For more details, see Copy Resources
Some Tips
Specifying resource directories
maven默认src/main/resources
下的资源。如果你有资源文件不是存放在这个目录下,那么可以通过<resources>
元素指定:
<project>
...
<build>
...
<resources>
<resource>
<directory>${basedir}/apk</directory>
<includes>
<include>**/*.apk</include>
</includes>
<targetPath>META-INF/apk</targetPath>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
...
</build>
...
</project>
Including and excluding files and directories
除了指定原资源文件和目标目录,我们还可以指定包含或者排除哪些目录或者文件。
例如:
<project>
...
<build>
...
<resources>
<resource>
<directory>${basedir}/sample</directory>
<targetPath>META-INF/sample</targetPath>
</resource>
<resource>
<directory>${basedir}/docs</directory>
<targetPath>META-INF/docs</targetPath>
</resource>
<!-- 把源代码打在一起,方便后面SDK打包 -->
<resource>
<directory>${project.build.sourceDirectory}</directory>
<includes>
<include>com/qq/buy/api/client/**/*.java</include>
</includes>
<targetPath>META-INF/source</targetPath>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
</build>
</project>
Resources Filter
最后,我们还可以对资源文件进行变量替换,这个maven称之为resources filter。变量值可以来自 system properties, project properties, filter resources 和 command line.
resources的三个goals都支持resources filter。
例如:
<project>
...
<build>
...
<resources>
<resource>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<filters>
<filter>config.properties</filter>
</filters>
</build>
</project>