4

When I build my project, I run this command :

mvn clean package

I'd like the resulting jar file built in the default target directory, during the package phase, be copied in another directory.

How can I do this with Maven?

random
  • 9,774
  • 10
  • 66
  • 83
Stephan
  • 41,764
  • 65
  • 238
  • 329
  • What is the intention to copy the created jar into a different directory ? – khmarbaise Apr 20 '11 at 11:21
  • @khmarbaise when I build my project with maven, I want it to be auto-deployed to my application server – Stephan Apr 20 '11 at 12:06
  • Than you should take a deeper look to the maven-cargo-plugin which can handle such things. Do you need to deploy for testing ? May be integration tests? (cargo will be good for both.) http://cargo.codehaus.org/Maven2+plugin. Furthermore (prod/test/dev)-deployment is not the intention of Maven. – khmarbaise Apr 20 '11 at 13:04
  • @khmarbaise *".. not the intention of Maven"* > That's why maven plugins exist, especially the `jboss-maven-plugin` : http://mojo.codehaus.org/jboss-maven-plugin/index.html – Stephan Apr 20 '11 at 13:57

2 Answers2

1

You can use the ant run plugin to copy the stuff over.

The following is taken from a pom from rhq-project.org

 <build>
    <plugins>

       <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.1</version>
          <executions>

             <execution>
                <id>deploy-jar-meta-inf</id>
                <phase>package</phase>
                <configuration>
                   <tasks>
                      <unjar src="${project.build.directory}/${project.build.finalName}.jar" dest="${rhq.deploymentDir}" overwrite="false">
                         <patternset>
                            <include name="META-INF/**" />
                         </patternset>
                      </unjar>
                   </tasks>
                </configuration>
                <goals>
                   <goal>run</goal>
                </goals>
             </execution>

             <execution>
                <id>undeploy</id>
                <phase>clean</phase>
                <configuration>
                   <tasks>
                      <property name="deployment.dir" location="${rhq.deploymentDir}" />
                      <echo>*** Deleting ${deployment.dir}${file.separator}...</echo>
                      <delete dir="${deployment.dir}" />
                   </tasks>
                </configuration>
                <goals>
                   <goal>run</goal>
                </goals>
             </execution>

          </executions>
       </plugin>
Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
1

By default the folder declared in Super POM, that have been inherited by your pom.

 <build>

 <directory>${project.basedir}/target</directory> 

</build>

You can change it in your pom.xml the next way:

 <build>
 <directory>${project.basedir}/yourFolder</directory>

</build>
Oleksandr
  • 2,346
  • 4
  • 22
  • 34
  • Actually, this target folder will have `classes`, `maven-archiver`, `war`, `myproject` directories and the jar file `myproject.war`. I would like to copy either myproject.war or the myproject directory only. – Stephan Apr 20 '11 at 12:01
  • 1
    For what? If you want to depoy your war there is some plug-in that will help you. For example for JBoss deployment I use: mvn clean package jboss:hard-deploy and my war file copied to deploy folder of the JBoss. – Oleksandr Apr 20 '11 at 12:53