Maven cargo:deploy

Update: added Pom file configuration section

Keith helped me get the Maven cargo deploy set up for me today, so instead of having to manually copy the .war file over to JBoss’s server\default\deploy directory after running the “Maven Clean Install” external tool I have set up, I can just run a Maven Deploy to Local JBoss, which will build the .war file and deploy it.

The changes I had to make were minimal:

Changes to settings.xml

In C:\Documents and Settings\myusername\.m2 I edited the settings.xml file to add the following:

<profiles>
<profile>
        <id>local-paths</id>
<properties>
            <jbossPath><em>D:\path\to\JBoss-install-dir</em></jbossPath>
            <jbossConfigPath><em>D:\path\to\JBoss-install-dir</em>\server\default</jbossConfigPath>
        </properties>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>local-paths</activeProfile>
</activeProfiles>

Eclipse External Tool configuration

The other component is the Eclipse External Tool configuration.

Name: Maven Deploy to Local JBoss
Location: ${env_var:M2_HOME}\bin\mvn.bat (you could just hardcode the path, but one benefit abstracting it buys us is the ability to share the resulting configuration file among developers)
Working Directory: ${project_loc}
Arguments: clean install cargo:deploy

Pom file configuration

The third part of the setup is to add the following to your project’s pom.xml file, as a child element of the <project> element:

<build>
<plugins>
<plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>jboss4x</containerId>
                        <home>${jbossPath}</home>
                    </container>
                    <configuration>
                        <type>existing</type>
                        <home>${jbossConfigPath}</home>
                    </configuration>
                    <deployer>
                        <type>installed</type>
                        <deployables>
                            <deployable>
                                <groupId>${pom.groupId}</groupId>
                                <artifactId>${pom.artifactId}</artifactId>
                                <type>${pom.packaging}</type>
                            </deployable>
                        </deployables>
                    </deployer>
                </configuration>
            </plugin>
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

(Those variables, such as ${jbossPath}, are magic to me — I don’t remember defining them, but it’s possible my Eclipse setup came with them already defined.)

Benefits

Of course, the immediate benefit of having this working Deploy external tool configuration is that when I want to build and deploy it’s now a one-step operation instead of two.  There’s a bigger benefit though:

When all day I’m making changes and deploying, I will often do something else while the .war file is being built.  It’s often a few minutes before I get back to copy the file over to JBoss, and by that time, I may not remember if I’ve made any more code changes since I last built.  So I re-run the install operation, this time waiting for it to complete (maybe).  There are probably many times that I rebuild when the .war already had the latest code changes, and that’s a waste of time and energy.  Having this tool available will eliminate that waste.

Advertisements

7 thoughts on “Maven cargo:deploy

  1. Thanks for this – helped me immensely.

    FYI – the ‘magic’ properties are simply taken from the settings.xml:

    becomes ${jbossPath}

    Neat!

  2. I’m glad it helped you! And thanks for explaining the magic… now I see the profiles -> profile -> properties -> jbossPath setting.

  3. What if I want to have the generated maven warfile deployed on a remote host? Here is the scenario:

    On server “A” have a perl/bash script checkout latest SVN version of a project, have maven build it and using the maven-cargodeploy place the generated war on server “B” then possibly bounce the server.

  4. Hi
    Good one, Thanks~! I am having a problem in that the war is getting deployed to the existing tomcat but without the name as “.war”. Very Strange, but I have set the name, finalName for the build etc etc without any success. Any ideas?
    thanks
    Vidhya

  5. Vidhya,

    Is it deploying successfully? If so, I wonder if it matters that the .war extension is missing.

    Beyond that, I am not in an enterprise Java environment right now to be familiar with this issue, but you might try the Cargo mailing lists.

    God bless,
    -Daniel-

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.