The plugin provides various methods of deployment to Tomcat:
These are described in more detail below.
The simplest way to deploy a WAR project to Tomcat is to type:
mvn tomcat:deploy
This goal will assemble and deploy the WAR file to Tomcat's manager using HTTP PUT.
To specify a different WAR file location, add a plugin configuration block to your pom.xml as follows:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0</version> <configuration> <warFile>path/to/my/warFile.war</warFile> </configuration> </plugin> ... </plugins> ... </build> ... </project>
The default location is ${project.build.directory}/${project.build.finalName}.war.
To avoid building a WAR file upon deployment, a WAR directory can instead be deployed to Tomcat by typing:
mvn war:exploded tomcat:exploded
To specify a different WAR directory location, add a plugin configuration block to your pom.xml as follows:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0</version> <configuration> <warDirectory>path/to/my/warDir</warDirectory> </configuration> </plugin> ... </plugins> ... </build> ... </project>
The default location is ${project.build.directory}/${project.build.finalName}.
To supply a context.xml when deploying a WAR directory, add a plugin configuration block to your pom.xml as follows:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0</version> <configuration> <mode>both</mode> </configuration> </plugin> ... </plugins> ... </build> ... </project>
The default context.xml file use is located at src/main/webapp/META-INF/context.xml.
To specify a different context.xml file location, add a plugin configuration block to your pom.xml as follows:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0</version> <configuration> <contextFile>path/to/my/contextFile.xml</contextFile> </configuration> </plugin> ... </plugins> ... </build> ... </project>
The default location is ${project.build.directory}/${project.build.finalName}/META-INF/context.xml.
To avoid copying resources to the build directory, the webapp source directory can be deployed to Tomcat by typing:
mvn war:inplace tomcat:inplace
To specify a different WAR directory location, add a plugin configuration block to your pom.xml as follows:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0</version> <configuration> <warSourceDirectory>path/to/my/warSourceDir</warSourceDirectory> </configuration> </plugin> ... </plugins> ... </build> ... </project>
The default location is ${basedir}/src/main/webapp.
To supply a context.xml when deploying a WAR directory to Tomcat, add a plugin configuration block to your pom.xml as follows:
<project> ... <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0</version> <configuration> <mode>both</mode> </configuration> </plugin> </plugins> </build> ... </project>
The default context.xml file used is located at src/main/webapp/META-INF/context.xml.
To specify a different context.xml file location, add a plugin configuration block to your pom.xml as follows:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0</version> <configuration> <contextFile>path/to/my/contextFile.xml</contextFile> </configuration> </plugin> ... </plugins> ... </build> ... </project>
The default location is ${project.build.directory}/${project.build.finalName}/META-INF/context.xml.
To simply deploy just a context.xml file to Tomcat:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0</version> <configuration> <mode>context</mode> </configuration> </plugin> ... </plugins> ... </build> ... </project>
mvn tomcat:deploy
The default context.xml file used is located at src/main/webapp/META-INF/context.xml.
To specify a different context.xml file location, add a plugin configuration block to your pom.xml as follows:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0</version> <configuration> <contextFile>path/to/my/contextFile.xml</contextFile> </configuration> </plugin> ... </plugins> ... </build> ... </project>
The default location is ${project.build.directory}/${project.build.finalName}/META-INF/context.xml.
A WAR project can be run under an embedded Tomcat server by typing:
mvn tomcat:run
To stop the embedded server, press CTRL+C.