JBoss Hot-Deploy With Maven

Posted by Tejus Parikh on February 3, 2010

If you’re a web-developer, one of the best features of Eclipse is the JBoss IDE plugin. The mere fact that you don’t have to re-compile/re-deploy the war for every change saves countless hours per build. If you don’t want to use Eclipse, you can replicate this behavior with Maven and run the app out of your working directory. The first step is to navigate to the location of your code (hereon referred to as $CODE_DIR) and execute the maven task:

$ mvn war:inplace

This will create the entire war structure in $CODE_DIR/src/main/webapp. Take a look. You’ll see a classes and lib directory under WEB-INF. This is probably a good time to exclude these directories from version control. I use Git, so I added the following lines to .gitignore at the top level of the project:



Now that you have a complete war you can have it deployed in jboss by creating a symlink. Assuming that $JBOSS_HOME is set, you need the following command:

ln -s $CODE_DIR/src/main/webapp $JBOSS_HOME/server/default/deploy/web.war

Startup JBoss and you can now edit your non-compiled resources, like Javascript, JSPs and CSS at will, without a compile/deploy cycle. If you want similar behavior for changes to code or libraries, there’s just one more step. Running:

mvn compile war:inplace

on its own won’t redeploy the classes. For that, you’ll need to touch the web.xml file. You can do this with the maven exec plugin. This part is Linux/Mac OSX only. If you’re on Windows, well you have bigger problems beyond hot-deploy. Open up $CODE_DIR/pom.xml and add the following lines:

Now running mvn compile war:inplace exec:exec will redeploy the project right from your working directory. I have this configuration mapped to a keystroke in Intellij to make the process seamless. The benefits of this approach is that it will work with any IDE or development environment. It also works with JBoss 4.2 and 5.0 (JBoss tools has had some issues with 5.0 because of the VFS changes). It also works every time. JBoss tools would occasionally not update static files. The downside is that it’s not as seamless nor as fast. It will redeploy the webapp, just as if you had pushed a new war. The time savings are still substantial and I would give this approach a try if you use an environment other than eclipse for your java development.

Related Posts:

Tejus Parikh

Tejus is an software developer, now working at large companies. Find out when I write new posts on twitter, via RSS or subscribe to the newsletter: