Jan 3, 2013

Deploying web applications using maven command line

Maven comes up with a powerful list of features and plugins for rapid application development, deployment and testing.

While developing web applications, the need is always felt to deploy, undeploy and redeploy applications using the command line. For apache tomcat, maven comes up with a tomcat-maven-plugin which facilitates the same.

1. Follow the steps mentioned in the post for creating a simple web application.
2. Add the below lines in your pom.xml. This will download the tomcat-maven-plugin jar in your local maven repository.

<build>
    <finalName>webapp</finalName>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <url>http://localhost:8080/manager/text</url>
                    <username>admin</username>
                    <password>admin</password>
                </configuration>
            </plugin>
    
        </plugins>
    </pluginManagement>
  </build>

Starting Apache Tomcat 7.0, you need to use http://localhost:8080/manager/text as your manager url. Earlier versions used http://localhost:8080/manager as the manager url.

Make sure you have added the user admin in the tomcat-users.xml configuration file under the conf directory and assigned the role manager-script for Apache Tomcat 7.0 OR manager role for Apache Tomcat 6.0

Listing all web applications
mvn tomcat:list

Deploying a web application
mvn tomcat:deploy

Undeploying a web application
mvn tomcat:undeploy

Redeploying a web application
mvn tomcat:redeploy

Stopping a web application
mvn tomcat:stop

Starting a web application
mvn tomcat:start

No comments :

Post a Comment