10.9 Hot-Deploying to JBoss

10.9.1 Problem

You want to deploy a new EAR or WAR file to JBoss.

10.9.2 Solution

Copy a new EAR to the deploy directory within the server environment that JBoss was started with.

10.9.3 Discussion

JBoss provides a simple mechanism to hot deploy: simply copy a new EAR file to the deploy directory within the server environment that JBoss was started with. This process is different from Tomcat; Tomcat requires the use of the Manager application. JBoss simply keeps tabs on the appropriate deploy directory, and when something new is discovered, it's deployed. If an old application exists then it is removed.

Here is an Ant target named deploy that copies an EAR file to JBoss, which is automatically installed:

<target name="deploy" depends="ear"
    description="Builds and deploys the project to JBoss.">
  <copy file="${dir.build}/${ear.file}" todir="${dir.jboss.deploy}"/>

The same target could be duplicated to copy a WAR file, too. The todir attribute is extremely important. The Ant property dir.jboss.deploy is defined as a well-known location within JBoss. Specifically, JBoss scans a directory for new deployed applications within the server environment that JBoss was started with. JBoss has three main default server environments:


The bare minimum needed to start JBoss 3.x. This environment contains only logging, JNDI, and a URL deployment scanner for hot deploying. An EJB container, JMS, and other services are not available.


The default server environment. This environment contains all services except for clustering and RMI\IIOP.


This environment provides all services available with the JBoss server.

This recipe simply uses the default server environment. Here are the Ant properties needed to set up the JBoss server environment and deployment directory:

<property name="jboss.server.config" value="default"/>
<property name="dir.jboss.deploy"    

Copying an EAR to the appropriate directory allows JBoss to automatically deploy your new application.

10.9.4 See Also

Recipe 10.3 shows how to use Tomcat's Manager web application to hot-deploy.