Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying files from my project in Maven

Tags:

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

like image 399
Gandalf StormCrow Avatar asked Aug 06 '10 12:08

Gandalf StormCrow


People also ask

Where do maven project data files go?

In a project that follows the mavenSW conventions, resources such as *. properties files can be placed in a src/main/resources directory. The files/folders in this directory will be copied to the root level of the jarW (or other similar package) that is generated for the project.

What is maven Basedir?

basedir : The directory that the current project resides in. This means this points to where your Maven projects resides on your system. It corresponds to the location of the pom. xml file.

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.

How does maven import work?

For the information on how to work with Maven projects, refer to Maven projects. For the auto-import settings, refer to Build Tools. Select this checkbox to specify the location of your project's files after the import. For example, when you import a project and want to keep the iml file and .


2 Answers

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> 
like image 95
JoseK Avatar answered Oct 03 '22 05:10

JoseK


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> 
like image 32
mort Avatar answered Oct 03 '22 04:10

mort