How to copy .war to Tomcat's webapps directory using Maven?

<build>
   <plugins>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
           <outputDirectory><!-- Tomcat webapps location--></outputDirectory>
           <!-- Example of Tomcat webapps location :D:\tomcat\webapps\ -->
        </configuration>
      </plugin>
    </plugins>
</build>

Once you have added it to your pom.xml, you can copy the WAR file by calling mvn package or mvn war:war.


I used the Maven WAR Plugin: http://maven.apache.org/plugins/maven-war-plugin/usage.html


This is the correct approach :

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
             <warName>${name}</warName>
             <outputDirectory>C:\Tomcat7\webapps</outputDirectory>
            </configuration>
        </plugin>

This will put a war file in C:\Tomcat7\webapps folder with the name of the maven project.