Copying files from my project in Maven

后端 未结 3 1800
走了就别回头了
走了就别回头了 2020-12-09 16:31

Is it possible to copy folders from my project to a certain location during some Maven phase? Does anybody know how?

相关标签:
3条回答
  • 2020-12-09 16:56

    A solution similar to @mort's one with maven-antrun-plugin 1.8:

    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.8</version>
      <executions>
        <execution>
          <id>copy</id>
          <phase>compile</phase>
          <configuration>
            <target>
              <copy file="sourceFile" tofile="targetFile"/>
            </target>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution> 
      </executions>
    </plugin>
    

    Note that <tasks> node is deprecated in favor of <target> node as of maven-antrun-plugin 1.5.

    0 讨论(0)
  • 2020-12-09 16:58

    The Maven way of doing this would be using the copy-resources goal in maven-resources-plugin

    From http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</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>
    
    0 讨论(0)
  • 2020-12-09 17:11

    Take a look at the maven-antrun plugin. You can copy a file in any maven phase like this:

        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.4</version>
          <executions>
            <execution>
              <id>copy</id>
              <phase>compile</phase>
              <configuration>
                <tasks>
                  <copy file="myFileSource" tofile="MyFileDest"/>
                </tasks>
              </configuration>
              <goals>
                <goal>run</goal>
              </goals>
            </execution> 
          </executions>
        </plugin>
    
    0 讨论(0)
提交回复
热议问题