Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy an entire directory into another directory using Maven?

Tags:

maven

I want to know how to copy an entire directory into another directory using Maven without using the Mmaven antrun plugin.

like image 284
galme Avatar asked Jul 25 '13 07:07

galme


People also ask

What is Maven clean plugin?

The Maven Clean Plugin, as the name implies, attempts to clean the files and directories generated by Maven during its build. While there are plugins that generate additional files, the Clean Plugin assumes that these files are generated inside the target directory.

What is resource directory in Maven?

Overview With the default Maven layout, we store resource files under the src/main/resources directory. After a build, Maven moves these files to the build output directory - target/classes. So they become available in the application classpath. There are cases where we have resource files under different directories.

How target folder is created in Maven?

The target directory is created by Maven. It contains all the compiled classes, JAR files etc. When executing the mvn clean command, Maven would clean the target directory. The webapp directory contains Java web application, if the project is a web application.

What does Maven resources plugin do?

The Resources Plugin handles the copying of project resources to the output directory. There are two different kinds of resources: main resources and test resources.


1 Answers

You can use the Maven resources plugin.

As an example taken from their documentation:

<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>

This would copy the content of the directory into the outputDirectory if I'm not mistaken.

like image 160
André Stannek Avatar answered Sep 18 '22 13:09

André Stannek