JBoss Application Deployment Tips and Build Sample Scripts
Overview
When it comes application builds/deployments in JBoss, there are a plethora of viable approaches. This wiki highlights several build/deploy scenerios, along with steps and pertinent build script samples. The following approaches are covered:
Point/click deployment using JBossIDE - For users that don't like ANT build scripts
Exploded EAR, JAR, SAR, WAR deployment (Option 1) - Maximize development productivity by eliminating ANT copy tasks
Exploded EAR, JAR, SAR, WAR deployment (Option 2) - Separate IDE from the compile, build and deploy process
Normal EAR, JAR, SAR, WAR deployment - Deploy a zipped archive (Necessary when using Clustering/Farm Deployment)
Point/Click Deployment Using JBossIDE
This approach is the preferred way if you refuse to use ANT.
Create a server instance in the Server Navigator View, if one does not exist. You can point to any working JBoss installation on your local machine or a remote machine.
Click Window > Click Show View > Click Other > Click JBoss-IDE > Click Server Navigator
Right Click in the Server Navigator View > Click Configuration > Click New > Specify Configuration Settings > Click Apply > Click Close
Right Click on any EAR, JAR, SAR, WAR or any folder named .ear, .jar, .sar, .war
Click Deploy To
Specify deployment target
Click OK
Exploded EAR, JAR, SAR, WAR Deployment (Option 1) WARNING - This approach will not work when deploying to a cluster via farm deployment!
This approach is the preferred way if you want to minimize build/deploy execution time by eliminating ANT copy tasks, and leveraging IDE complilation versus build script compilation.
Make sure your IDE workspace folder is named YOUR_APPLICATION_NAME.ear, YOUR_APPLICATION_NAME.war, etc...
Point the JBoss DeploymentScanner to your development workspace
Open $JBOSS_HOME/server/default/conf/jboss-service.xml
Edit the "URLs" attribute entry
<!-- Make sure your YOUR_APPLICATION_NAME.ear directory is a sub-directory in YOUR_WORKSPACE_LOCATION --> <attribute name="URLs"> deploy/, YOUR_WORKSPACE_LOCATION </attribute>
Create a simple ANT task that touches the EAR, JAR, SAR, WAR main config file. This step is needed because the DeploymentScanner only re-deploys exploded archives when the main config file changes.
<!-- Deploy or re-deploy an EAR --> <target name="deploy-ear"> <touch file="$YOUR_WORKSPACE_LOCATION/YOUR_APPLICATION_NAME.ear/META-INF/application.xml"></touch> </target> <!-- Deploy or re-deploy an JAR --> <target name="deploy-jar"> <touch file="$YOUR_WORKSPACE_LOCATION/YOUR_APPLICATION_NAME.jar/META-INF/ejb-jar.xml"></touch> </target> <!-- Deploy or re-deploy an SAR --> <target name="deploy-sar"> <touch file="$YOUR_WORKSPACE_LOCATION/YOUR_APPLICATION_NAME.sar/META-INF/jboss-service.xml "></touch> </target> <!-- Deploy or re-deploy a WAR --> <target name="deploy-war"> <touch file="$YOUR_WORKSPACE_LOCATION/YOUR_APPLICATION_NAME.war/WEB-INF/web.xml"></touch> </target>
Exploded EAR, JAR, SAR, WAR Deployment (Option 2) WARNING - This approach will not work when deploying to a cluster via farm deployment!
This approach is the preferred way if you want to de-couple the IDE from compilation, build and deployment.
Point the JBoss DeploymentScanner to an application archive. (Not necessary, but recommended)
Open $JBOSS_HOME/server/default/conf/jboss-service.xml
Edit the "URLs" attribute entry
<!-- This will allow you to place your applications in an isolated location --> <attribute name="URLs"> deploy/, $JBOSS_HOME/server/myapps </attribute>
Create an ANT task that compiles the Java classes.
<!-- Compile --> <target name="compile"> <javac srcdir="SOURCE_DIR" destdir="CLASSES_DIR"> <classpath> <fileset dir="LIB_DIR}"> <include name="*.jar" ></include> </fileset> </classpath> </javac> </target>
Create an ANT task that builds the exploded archive.
<target name="build" depends="compile"> <!-- This task will be unique to your application type/structure. The end result should be a fully built YOUR_APPLICATION_NAME.ear, YOUR_APPLICATION_NAME.war, etc... archive directory that can be copied or FTP'd to a JBoss deployment location. This should be an exploded archive, not a zipped distribution. --> <mkdir dir="BUILD_DIR/YOUR_APPLICATION_NAME.ear" ></mkdir> <copy todir="BUILD_DIR/YOUR_APPLICATION_NAME.ear"> <fileset dir="???"> <include name="???" ></include> </fileset> <fileset dir="???"> <include name="???" ></include> </fileset> </copy> </target>
Create an ANT task that deploys the exploded archive changes.
<target name="deploy" depends="compile"> <!-- This task will be unique to your environment. You could choose to deploy the application locally (copy) or remotely via (ftp or scp). Refer to the Ant manual for help with ftp or scp --> <mkdir dir="DEPLOY_DIR/YOUR_APPLICATION_NAME.ear" ></mkdir> <copy todir="$JBOSS_HOME/server/myapps/YOUR_APPLICATION_NAME.ear"> <fileset dir="BUILD_DIR" ></fileset> </copy> </target>
Create a simple ANT task that touches the EAR, JAR, SAR, WAR main config file. This step is needed because the DeploymentScanner only re-deploys exploded archives when the main config file changes.
<!-- Deploy or re-deploy an EAR --> <target name="re-deploy-ear" depends="deploy"> <touch file="$JBOSS_HOME/server/myapps/YOUR_APPLICATION_NAME.ear/META-INF/application.xml"></touch> </target> <!-- Deploy or re-deploy an JAR --> <target name="re-deploy-deploy-jar" depends="deploy"> <touch file="$JBOSS_HOME/server/myapps/YOUR_APPLICATION_NAME.jar/META-INF/ejb-jar.xml"></touch> </target> <!-- Deploy or re-deploy an SAR --> <target name="re-deploy-deploy-sar" depends="deploy"> <touch file="$JBOSS_HOME/server/myapps/YOUR_APPLICATION_NAME.sar/META-INF/jboss-service.xml"></touch> </target> <!-- Deploy or re-deploy a WAR --> <target name="re-deploy-deploy-war" depends=deploy"> <touch file="$JBOSS_HOME/server/myapps/YOUR_APPLICATION_NAME.war/WEB-INF/web.xml"></touch> </target>
Normal EAR, JAR, SAR, WAR deployment This approach will work when deploying to a cluster via farm deployment!
This approach is the preferred way if you want to deploy a standard, zipped archive to a clustered environment. But, for development purposes, this approach takes too long to build.
Create an ANT task that compiles the Java classes.
<!-- Compile --> <target name="compile"> <javac srcdir="SOURCE_DIR" destdir="CLASSES_DIR"> <classpath> <fileset dir="LIB_DIR}"> <include name="*.jar" ></include> </fileset> </classpath> </javac> </target>
Create an ANT task that builds the exploded archive.
<target name="build" depends="compile"> <!-- This task will be unique to your application type/structure. The end result should be a fully built YOUR_APPLICATION_NAME.ear, YOUR_APPLICATION_NAME.war, etc... archive directory that can be copied or FTP'd to a JBoss deployment location. This should be an exploded archive, not a zipped distribution. --> <mkdir dir="BUILD_DIR/YOUR_APPLICATION_NAME.ear" ></mkdir> <copy todir="BUILD_DIR/YOUR_APPLICATION_NAME.ear"> <fileset dir="???"> <include name="???" ></include> </fileset> <fileset dir="???"> <include name="???" ></include> </fileset> </copy> </target>
Create an ANT task that zips, then deploys the exploded archive.
<target name="deploy" depends="compile"> <mkdir dir="TEMP_DIR/YOUR_APPLICATION_NAME.ear" ></mkdir> <zip destfile="TEMP_DIR/YOUR_APPLICATION_NAME.ear" basedir="BUILD_DIR/YOUR_APPLICATION_NAME.ear" ></zip> <!-- This task will be unique to your environment. You could choose to deploy the application locally (copy) or remotely via (ftp or scp). Refer to the Ant manual for help with ftp or scp --> <copy todir="$JBOSS_HOME/server/all/farm/YOUR_APPLICATION_NAME.ear"> <fileset dir="TEMP_DIR" ></fileset> </copy> </target>
MWaschkowski: There is a typo when referring to the ant scripts - for ear,jar the file suggested to be touched is jboss-service.xml. It should be the files
.EAR
META-INF/application.xml
.JAR
META-INF/ejb-jar.xml
as shown here:
(I already got that page updated, just finishing the job for this page)
Thanks,
Mark
Comments