Maven构建之插件之——maven-resources-plugin

1. resources插件的功能

      resources插件的功能就是把项目需要的配置文件拷贝到指定的目录,默认是拷贝src\main\resources目录下的配置文件到classes目录下,而且我们可以配置源目录和输出目录。resources插件一般不单独执行,complie插件执行时会先调用resources插件,会将src\java下的代码编译成字节码和resources目录下的文件都输出到target\classes目录下。

2. 配置源目录和输出目录

<plugin>  
         <groupId>org.apache.maven.plugins</groupId>  
         <artifactId>maven-resources-plugin</artifactId>  
         <version>2.6</version>  
         <executions>  
           <execution>  
              <id>copy-resources</id>  
              <!-- 在default生命周期的validate阶段就执行
                resources插件的copy-resources目标 -->  
              <phase>validate</phase>  
              <goals>  
                <goal>copy-resources</goal>  
              </goals>  
              <configuration>  
              <!-- 指定resources插件处理资源文件到哪个目录下 -->  
                  <outputDirectory>${project.build.outputDirectory}</outputDirectory>  
                  <!-- 也可以用下面这样的方式(指定相对url的方式指定outputDirectory)
                  <outputDirectory>target/classes</outputDirectory> -->  
                  <!-- 待处理的资源定义 -->  
                  <resources>  
                      <resource>  
                      <!-- 指定resources插件处理哪个目录下的资源文件 -->                                                 
                  <directory>
                        src/main/${deploy.env}/applicationContext.xml
                  </directory>  
                      <!-- 指定不需要处理的资源 
                <excludes> 
                    <exclude>WEB-INF/*.*</exclude> 
                </excludes> -->  
                      <!-- 是否对待处理的资源开启过滤模式 
                           (resources插件的copy-resources目标也有资源过滤的功能,
                           这里配置的这个功能的效果跟<build><resources><resource>
                           下配置的资源过滤是一样的,只不过可能执行的阶段不一样, 
                           这里执行的阶段是插件指定的validate阶段,
                           <build><resources><resource>下的配置
                           将是在resources插件的resources目标执行时起作用
                           (在process-resources阶段)) -->  
                        <filtering>false</filtering>  
                     </resource>  
                  </resources>  
              </configuration>  
              <inherited></inherited>  
           </execution>  
         </executions>  
         </plugin>  

补充:${project.build.outputDirectory}使用properties文件设置环境变量:

project.build.outputDirectory:${PROJECT_BUILD_OUTPUTDIRECTORY:com/calm_encode/project/build/outputDirectory}

发布了22 篇原创文章 · 获赞 5 · 访问量 2190

猜你喜欢

转载自blog.csdn.net/calm_encode/article/details/103927111