It's possible to change the target build path where the war
file is placed on mvn package
by:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputDirectory>my\target\folder</outputDirectory>
</configuration>
</plugin>
Question: how can I create the war file in the default /target
, folder, but additionally copy the war file to one (or multiple) other destinations after build?
A simple way to do that would be to bind an execution of the maven-antrun-plugin
to the package
phase. The advantage is that you don't need to re-execute the maven-war-plugin
like mentioned in this answer.
This execution would copy the main artifact to the folder /path/to/folder
.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<copy file="${project.build.directory}/${project.build.finalName}.war"
todir="/path/to/folder" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
(This snippet must be placed inside the <build><plugins>
element).
Running mvn clean install
(or "Run As... > Maven Install" in Eclipse), Maven will do what you want. ${project.build.directory}/${project.build.finalName}.war
refers to the main WAR artifact present in the build directory (which is target
by default).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With