Remote deploy to a Tomcat Server using Maven 3
1. Install maven tomcat7 plugin (you need manager application in tomcat7 – comes by default)
1 2 3 4 5 6 7 8 9 10 |
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <url>http://10.0.0.11:8080/manager/text</url> <server>tomcat</server> <path>/MyApp</path> </configuration> </plugin> |
2. Configure maven settings.xml in ~/.m2/ (or the place where maven is reading settings.xml)
1 2 3 4 5 |
<server> <id>tomcat</id> <username>my_user</username> <password>my_password</password> </server> |
3. Configure tomcat users in /usr/share/apache-tomcat-7.0.39/conf/tomcat-users.xml
1 2 3 4 5 6 7 8 9 10 |
<tomcat-users> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <role rolename="admin-gui"/> <role rolename="admin-script"/> <user username="my_user" password="my_password" roles="manager-gui,manager-script,manager-jmx, manager-status,admin-gui,admin-script"/> </tomcat-users> |
4. Execute Maven goals
1 2 3 |
org.apache.tomcat.maven:tomcat7-maven-plugin:2.1:undeploy clean org.apache.tomcat.maven:tomcat7-maven-plugin:2.1:deploy |
5. Tips and Tricks
It is preferable to have a maven profile for each server (DEV, TEST, PROD), in case you have database connections and servers are different. In this way, your war file will be build with predefined IP addresses and parameters for each particular deploy.