Deploy to Tomcat7 server with Maven - bahkified/Notes GitHub Wiki
This assumes that Tomcat7 instance is up and running somewhere.
in pom.xml
, use the tomcat7-maven-plugin:
<build>
…
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- Maven Tomcat Plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:10081/manager/text</url> <!-- point this to your tomcat server, keeping /manager/text suffix -->
<server>LENSc2</server> <!-- This is the ID of your server as defined in settings.xml -->
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
<!-- Maven compiler plugin -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
…
</build>
On the tomcat server, make sure the correct roles/users are defined in tomcat-users.xml
, which is located at $TOMCAT_HOME/conf/
<tomcat-users>
<role rolename="manager-script"/> <!-- used to access the manager/text endpoint -->
<role rolename="manager-gui"/> <!-- used to access the manager/html endpoint -->
<role rolename="manager-jmx"/> <!-- used to access the manager/jmx (?) endpoint -->
<user username="admin" password="Password1" roles="manager-script"/>
</tomcat-users>
Define the server in the Maven settings. Maven global settings (will be applied for all users on the machine) are located at $MAVEN_HOME/conf/settings.xml
(root level)
<servers>
<server>
<id>LENSc2</id>
<username>admin</username>
<password>Password1</password>
<server>
</servers>
…
The ID field is the ID that is referenced in the <server>
tag in the maven plugin. And the username/password are for the Tomcat user with the correct roles.
Assuming the settings are correct, you just need to execute the mvm tomcat7:deploy
command. This will deploy the WAR file to the tomcat server.