Maven script for deploying project to Apache Tomcat on Amazon EC2

In the Deploying web application on remote tomcat post i listed steps for creating maven script that can install web application on remote Apache Tomcat. You could use the same concept to deploy web applications to Apache Tomcat running on Amazon EC2, by following these steps
  1. First change the tomcat-users.xml to add tomcatadmin user and give him manager-gui and manager-script roles
    
    <?xml version='1.0' encoding='utf-8'?>
    <tomcat-users>
    <role rolename="tomcat"/>
    
    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
        
    <user username="tomcatadmin" password="tomcatadmin" roles="tomcat,manager-gui,manager-script"/>
    
    <user username="both" password="tomcat" roles="tomcat"/>
    <user username="role1" password="tomcat" roles="role1"/>
    </tomcat-users>
    
  2. Next change your <MVN_HOME>/settings.xml file to add AWSServer server with tomcatadmin as username passowrd, you shoudl use the user id password that you set in your tomcat-users.xml file here
    
     <server>
          <id>AWSServer</id>
          <username>tomcatadmin</username>
          <password>tomcatadmin</password>
      </server>
    
  3. Last step is to add following plugin to you pom.xml, in this value of url will be the ec2 instance DNS name and the value of server would be equal to id of server you set in settings.xml
    
     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
            <url>http://ec2-54-84-128-249.compute-1.amazonaws.com:8080/manager/text</url>
            <server>AWSServer</server>
            <path>/simplewebapp</path>
        </configuration>
    </plugin>
    
  4. Now execute mvn tomcat:redeploy to deploy your code to tomcat

2 comments:

Cristian Placintar said...

I knew it must be possible.
Works flawlessly. Thank you!

wapppictures said...

Wow! Totally what I needed.