Maven cargo:deploy
Posted by danielmeyer on July 25, 2008
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.
Mike Burke said
Thanks for this – helped me immensely.
FYI – the ‘magic’ properties are simply taken from the settings.xml:
becomes ${jbossPath}
Neat!
Mike Burke said
sorry, no preview:
<jbossPath> becomes ${jbossPath}
danielmeyer said
I’m glad it helped you! And thanks for explaining the magic… now I see the profiles -> profile -> properties -> jbossPath setting.