0

mvn package at specified location (ex. C:\Users\xyz)

For example

mvn package or mvn compile war:war command will generate a war file at ../projectName/target location

but insted of that target location can we specify our own location using command line ?

Ketan Patel
  • 91
  • 1
  • 2
  • 7

2 Answers2

1

No. Maven is convention over configuration. However you can copy the file afterwards, using a variety of mechanisms explained here: Best practices for copying files with Maven

Community
  • 1
  • 1
Mikkel Løkke
  • 3,710
  • 23
  • 37
0

It is not possible out of the box. But you could prepare your POM for that:

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

If you now do a simple mvn package it will behave as default: putting the output into the project's target directory.

But you also now can run a

mvn package -DbuildDirectory=<any other directory>

and all output is done to the new place. Note, that I said: all output! It is not only the artifact (the JAR or the WAR), but all compiled classes, the surefire reports, and so on.

Seelenvirtuose
  • 20,273
  • 6
  • 37
  • 66