【问题标题】:Use maven to copy files使用maven复制文件
【发布时间】:2015-10-05 16:29:25
【问题描述】:

我需要使用 maven 来复制一些文件。这是我的文件夹结构的样子: `

+code
    +trunk
        +delivery
            -pom.xml
        +myFramework
            +catalog
                -pom.xml
                +target
                    +classes
                        -catalog.properties
                        -catalog.xml
            +orders
                -pom.xml
                +target
                    +classes
                        -orders.properties
                        -orders.xml
            +common
                -pom.xml
                +target
                    +classes
                        -common.properties
                        -common.xml
            -pom.xml
        +myOther
            +stuff
                +moreStuff
                    +target
                        +classes
                            -moreStuff.properties
                    -pom.xml
                -pom.xml
            -pom.xml
        +Test
        -pom.xml
+distros
    +dome`

加号(+)是目录,减号(-)是文件。

我必须对交付文件夹中的 pom.xml 进行更改。需要发生的事情是将目录、订单、common 和 moreStuff 文件夹中的属性和 xml 文件复制到 dome 文件夹中。

所以delivery pom执行后的最终结果是dome目录包含catalog.properties、catalog.xml、orders.properties、orders.xml、common.properties、common.xml和moreStuff.properties。

【问题讨论】:

  • 我认为这与您可以使用程序集插件执行的操作完全匹配:maven.apache.org/plugins/maven-assembly-plugin(假设您要创建可分发文件)。否则资源插件应该已经能够做你想做的事了。目录结构有那么重要吗?是否可以将 distros 文件夹移动到最顶层 pom.xml 级别的 target/ 中?这将简化路径处理。

标签: maven


【解决方案1】:

我对根 pom(在树干下)而不是交付 pom 进行了更改。这就是我最终这样做的方式:

<build>
   <plugins>
      <plugin>
         <artifactId>maven-resources-plugin</artifactId>
         <version>2.6</version>
         <executions>
            <execution>
               <id>copy-resources</id>
               <phase>process-resources</phase>
               <goals>
                  <goal>copy-resources</goal>
               </goals>
               <configuration>
                  <outputDirectory>C:/distros/dome</outputDirectory>
                  <resources>
                     <resource>
                        <directory>src\main\resources</directory>
                        <excludes>
                           <exclude> ... </exclude>
                        </excludes>
                        <filtering>true</filtering>
                     </resource>
                  </resources>
               </configuration>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>

我没有从 target/classes 文件夹中复制它们,而是从 src/main/resources 文件夹中复制了资源文件(原始问题中未指明)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多