Question

I have a Java application, which runs inside web container (Jetty at the moment) and responds to requests via web services.

Now I want to create a mechanism, which allows to deploy (transfer the WAR file to the server, install the new version there) a new version of the application to Amazon EC2 instance as easily as possible (ideally - by running some Maven command).

I'm using Beanstalk for my version control and they offer deployment support, but I couldn't figure out how to apply it to my scenario.

Are there any tutorials on how to deploy web applications to Amazon EC2 with Maven (with or without Beanstalk) ?

Update 1 (10.04.2013): Beanstalk staff has recommended me to use SSH deployments.

Update 2 (11.04.2013 23:17 MSK):

In my first attempt to use Maven Cargo plugin, I added following stuff to my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    [...]
    <build>
    [...]    
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>Heaven7</containerId>
                        <type>remote</type>
                    </container>
                    <configuration>
                        <type>runtime</type>
                        <properties>
                            <cargo.remote.username>myusername</cargo.remote.username>
                            <cargo.remote.password>mypassword</cargo.remote.password>
                        </properties>
                    </configuration>

                    <!-- Deployer configuration -->
                    <deployer>
                        <type>remote</type>
                    </deployer>

                    <deployables>
                        <deployable>
                            <groupId>ru.mycompany</groupId>
                            <artifactId>my-product</artifactId>
                            <type>war</type>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>
        </plugins>
    </build>
    [...]
</project>

Then I ran mvn cargo:deploy and got following output:

[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.3.3:dep
oy (default-cli) on project [...]: Execution default-cli of goal org.codeh
us.cargo:cargo-maven2-plugin:1.3.3:deploy failed: Cannot create configuration.
here's no registered configuration for the parameters (container [id = [Heaven7
, type = [remote]], configuration type [runtime]). Actually there are no valid
ypes registered for this configuration. Maybe you've made a mistake spelling it

2 questions:

  1. How can I fix it?
  2. Where can I specify the address my Tomcat container?

Update 3 (12.04.2013 22:36 MSK):

I changed the section related to Cargo plugin like this:

    <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.3.3</version>
        <configuration>
            <container>
                <containerId>tomcat7</containerId>
                <type>remote</type>
            </container>
            <configuration>
                <type>runtime</type>
                <properties>
                    <cargo.remote.username>myuser</cargo.remote.username>
                    <cargo.remote.password>mypassword</cargo.remote.password>
                    <cargo.hostname>ec2-NN-NNN-NN-NN.compute-1.amazonaws.com</cargo.hostname>
                    <cargo.protocol>http</cargo.protocol>
                    <cargo.servlet.port>8080</cargo.servlet.port>
                </properties>
            </configuration>

            <!-- Deployer configuration -->
            <deployer>
                <type>remote</type>
            </deployer>
            <deployables>
                <deployable>
                    <groupId>ru.mycompany</groupId>
                    <artifactId>myproduct</artifactId>
                    <type>war</type>
                </deployable>
            </deployables>

        </configuration>
    </plugin>
</plugins>

Then I executed mvn cargo:deploy and got this output:

[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.3.3:depl
oyer-deploy (default-cli) on project ccp-server: Execution default-cli of goal o
rg.codehaus.cargo:cargo-maven2-plugin:1.3.3:deployer-deploy failed: Cannot creat
e configuration. There's no registered configuration for the parameters (contain
er [id = [tomcat7], type = [remote]], configuration type [runtime]). Actually th
ere are no valid types registered for this configuration. Maybe you've made a mi
stake spelling it? -> [Help 1]

Update 4 (12.04.2013 23:12):

I changed pom.xml once again to:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.3.3</version>
    <configuration>
        <container>
            <containerId>tomcat7x</containerId>
            <type>remote</type>
        </container>
        <configuration>
            <type>runtime</type>
            <properties>
                <cargo.remote.username>myuser</cargo.remote.username>
                <cargo.remote.password>mypassword</cargo.remote.password>
                <cargo.hostname>ec2-NN-NNN-NN-NN.compute-1.amazonaws.com</cargo.hostname>
                <cargo.protocol>http</cargo.protocol>
                <cargo.servlet.port>8080</cargo.servlet.port>
            </properties>
        </configuration>

        <!-- Deployer configuration -->
        <deployer>
            <type>remote</type>
        </deployer>
        <deployables>
            <deployable>
                <groupId>ru.mycompany</groupId>
                <artifactId>myproduct</artifactId>
                <type>war</type>
            </deployable>
        </deployables>

    </configuration>
</plugin>

Then, I used following commands to deploy my application to the server:

  1. mvn clean
  2. mvn install
  3. mvn cargo:deploy

Please note that <packaging> must be set to war in order for this sequence to work (otherwise you may get strange error messages).

Was it helpful?

Solution 2

Please correct me if I'm wrong. I understand that you're using the Tomcat version 7. The Cargo configuration for Tomcat 7 should be as the following: -

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.3.3</version>
    <configuration>
        <container>
            <containerId>tomcat7x</containerId>
            <type>remote</type>
        </container>
        <configuration>
            <type>runtime</type>
            <properties>
                <cargo.remote.username>myusername</cargo.remote.username>
                <cargo.remote.password>mypassword</cargo.remote.password>
                <cargo.hostname>MY_HOST</cargo.hostname>
                <cargo.protocol>http</cargo.protocol>
                <cargo.servlet.port>SERVER_PORT</cargo.servlet.port>
            </properties>
        </configuration>
        <!-- Deployer configuration -->
        <deployer>
            <type>remote</type>
            <deployables>
                <deployable>
                    <groupId>ru.mycompany</groupId>
                    <artifactId>my-product</artifactId>
                    <type>war</type>
                    <properties>
                        <context>MY_CONTEXT</context>
                    </properties>
                </deployable>
            </deployables>
        </deployer>
    </configuration>
</plugin>

Please note that

  1. <cargo.hostname> is the remote host name or ip address.
  2. <cargo.protocol> is either http or https.
  3. <cargo.servlet.port> is the remote port based on the <cargo.protocol>, e.g. 8080 or 8443
  4. <context> is the context name to use when deploying the web application.

Please refer to Cargo: Tomcat 7.x and Maven2 Plugin Reference Guide for further information.

I hope this may help.

OTHER TIPS

You could use the cargo maven plugin to deploy on a remote server. See this example for a remote deployment on a Tomcat server : Maven: How do I deploy my WAR file to a remote Tomcat server?

As Charlee and Dmitri answered earlier, the cargo plugin would usually be the easiest way to go. While doing that, you might also consider the way you actually create your EC2 instances (as in many scenarios, both dev/test ones and production ones) you would like to always create fresh instances (see Martin Fowler's thoughts on this at http://martinfowler.com/bliki/PhoenixServer.html and http://martinfowler.com/bliki/SnowflakeServer.html .

An interesting solution for doing so is provided by Ravello Systems, which basically lets you easily create a full blown replica of an application in the cloud, and they even implemented a maven plugin to help in automating that. Take a look at http://www.ravellosystems.com/blog/ravello_maven_plugin/ - you can tie the whole process together end-to-end with maven - from creating the environment to deploying the application, testing it, and tearing it down.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top