Maven: How to change the path to the target directory from the command line?

Maven: How to change the path to the target directory from the command line?

(I want to use a different target directory in some cases)

+59
java maven maven-2
Oct 11 '10 at 16:17
source share
3 answers

You must use profiles.

<profiles> <profile> <id>otherOutputDir</id> <build> <directory>yourDirectory</directory> </build> </profile> </profiles> 

And run maven with your profile

 mvn compile -PotherOutputDir 

If you really want to define your directory from the command line, you can do something like this ( NOT recommended at all ):

 <properties> <buildDirectory>${project.basedir}/target</buildDirectory> </properties> <build> <directory>${buildDirectory}</directory> </build> 

And compile like this:

 mvn compile -DbuildDirectory=test 

This is because you cannot change the destination directory using -Dproject.build.directory

+61
Oct 11 '10 at 16:23
source share

Colin is right to use a profile. However, his answer rigidly sets the target directory in the profile. An alternative solution would be to add a profile like this:

  <profile> <id>alternateBuildDir</id> <activation> <property> <name>alt.build.dir</name> </property> </activation> <build> <directory>${alt.build.dir}</directory> </build> </profile> 

This can affect the change of the assembly directory to everything that is set using the alt.build.dir property, which can be set in the POM, in user settings, or on the command line. If the property is missing, compilation will occur in the regular target directory.

+23
Sep 26
source share

My decision:

  • in pom.xml:

      <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.2</version> <configuration> <outputDirectory>${dir}</outputDirectory> </configuration> </plugin> 
  • in bash:

    mvn package -Ddir="/home/myuser/"

+5
Mar 12 '13 at 5:41
source share



All Articles