Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy war file to multiple folders?

Tags:

java

maven

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?

like image 478
membersound Avatar asked Jan 25 '16 10:01

membersound


1 Answers

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).

like image 101
Tunaki Avatar answered Oct 19 '22 03:10

Tunaki