Monday, March 3, 2014

Deploy to Tomcat 7 using Maven

Steps to deploy war file in Tomcat 7 through Maven:

1. tomcat-users.xml: This file is present at conf directory under tomcat folder (apache-tomcat-7.x/conf)

   Add role "manager-script". This is required in tomcat 7 if deployment is done through a script, like maven.
   Create a user by any name and give a password of your choice and assign this user with the "manage-script" role.
 
   Eg:

      <tomcat-users>

<role rolename="manager-script"/>
        <user username="admin" password="admin"  roles="manager-script"/>

      </tomcat-users>

For deploying to tomcat through eclipse, above roles will suffice. However, to manage through tomcat manager UI, additional roles needs to be added the use.

Note that for Tomcat 7 onwards, the roles required to use the manager application were changed from the single manager role to the following four roles. You will need to assign the role(s) required for the functionality you wish to access.

manager-gui - allows access to the HTML GUI and the status pages
manager-script - allows access to the text interface and the status pages
manager-jmx - allows access to the JMX proxy and the status pages
manager-status - allows access to the status pages only


 2. Setup the tomcat server in maven's settings.xml, under servers.
   
 <server>
<id>TomcatServer</id>
<username>admin</username>
<password>admin</password>
      </server>

 3. In the pom.xml, add the below plugin:

            <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
   <!-- Manager path in tomcat 7 is different than other versions of tomcat. -->
<url>http://localhost:8080/manager/text</url>
<!-- This is the server ID, given in the settings.xml -->
<server>TomcatServer</server>
<path>/exampleApplication</path>
</configuration>
</plugin>

Note that tomcat 7 has a different manager path than other versions of tomcat.

  4. Use command: mvn tomcat:deploy to deploy war file and command: mvn tomcat:redeploy to redeploy the web application. 

No comments:

Post a Comment