Maven-Resouces的介绍

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>     

转载于:https://my.oschina.net/u/561701/blog/1510868

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值