12

我想知道如何在不使用 Mmaven antrun 插件的情况下使用 Maven 将整个目录复制到另一个目录中。

4

2 回答 2

18

您可以使用Maven 资源插件

作为从他们的文档中获取的示例:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/non-packaged-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

如果我没记错的话,这会将 的内容复制directory到 中。outputDirectory

于 2013-07-25T07:55:20.287 回答
0

您可以使用https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html

<?xml version="1.0" encoding="UTF-8"?>
<build>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
         <version>3.1.2</version>
         <executions>
            <execution>
               <id>copy</id>
               <phase>package</phase>
               <goals>
                  <goal>copy</goal>
               </goals>
            </execution>
         </executions>
         <configuration>
            <artifactItems>
               <artifactItem>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>3.8.1</version>
                  <type>jar</type>
                  <overWrite>false</overWrite>
           <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                  <destFileName>optional-new-name.jar</destFileName>
               </artifactItem>
            </artifactItems>
            <outputDirectory>${project.build.directory}/wars</outputDirectory>
            <overWriteReleases>false</overWriteReleases>
            <overWriteSnapshots>true</overWriteSnapshots>
         </configuration>
      </plugin>
   </plugins>
</build>
于 2020-06-30T11:07:59.160 回答