Thursday, 10 November 2011

Deploying your web application to TomCat 7.0 using Maven

Deploying your web-application using the tomcat-maven-plugin can be done by as follows:
1. Create a user in Tomcat with the manager-script role. Before Tomcat 7.0, this was accomplished using the manager role. The user details can be sepecifed in the conf/tomcat-users.xml file as follows:


2. Now you need to tell maven that it can deploy applications to Tomcat using this role.
To set this connection, open your settings.xml file which should be present .m2 directory. Search for 'server' and put in the following credentials:

      localhost
      tom
      cat
    
Obviously, the server name is :localhost in this case.
3. In your maven pom.xml configure the tomcat-maven-plugin as follows:



            org.codehaus.mojo
            tomcat-maven-plugin
            
               http://localhost:8080/manager/text
                     localhost
                     /project_context
            
        



Take note of the
http://localhost:8080/manager/text
This is important otherwise you will keep getting 403:Access Forbidded errors when you attempt to deploy.

  • To build you war and deploy on Tomcat, use : mvn tomcat:deploy
  • To redploy your war, use : mvn tomcat:redeploy
  • To undeploy your war, use : mvn tomcat:undeploy

0 comments: