Create EAR deploy JBoss Server Hello World
If you want to create enterprise java application to run on JBoss application server with ant build file please have sample application below:
- Final project structure:
- application.xml:
<?xml version="1.0" encoding="UTF-8"?> <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" id="Application_ID" version="5"> <display-name>EnterpriseApplication</display-name> <module> <web> <web-uri>EARDeployment.war</web-uri> <context-root>EARDeployment</context-root> </web> </module> </application>
- web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>EARDeployment</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
- index.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> EAR deployment test -- Hello World! </body> </html>
- build.xml:
<?xml version="1.0" encoding="UTF-8"?> <project name="Jboss Ear Deployment EARProject" default="all" basedir="."> <property name="dirs.base" value="${basedir}" /> <property name="src" value="${dirs.base}/src" /> <property name="web" value="${dirs.base}/WebContent" /> <property name="classdir" value="${basedir}/build/classes" /> <property name="deploymentdescription" value="${dirs.base}/build/ear" /> <property name="dir.deploy.folder" value="C:\JavaHonk\jboss-5.1.0.GA\server\default\deploy" /> <property name="warFile" value="EARDeployment.war" /> <property name="earFile" value="EARDeployment.ear" /> <property name="earDir" value="${dirs.base}/build/ear" /> <property name="warDir" value="${dirs.base}/build/war" /> <target name="clean" description="Remove all generated files."> <delete dir="${warDir}/WEB-INF" /> <delete dir="${warDir}/WEB-INF/classes" /> <delete file="${earDir}/${warFile}" /> <delete file="${dirs.base}/${earFile}" /> <echo message="Cleaned" /> </target> <target name="clean_folder" description="Remove all generated files."> <delete dir="${warDir}/WEB-INF" /> <delete dir="${warDir}/WEB-INF/classes" /> <delete file="${earDir}/${warFile}" /> <delete file="${dirs.base}/${earFile}" /> <echo message="Cleaned" /> </target> <!-- Main target --> <target name="all" depends="clean,buildWar,buildEar,deploy" /> <!-- Create the War File --> <target name="buildWar"> <fileset dir="${classdir}" includes="**/*.class" /> <fileset dir="${web}" includes="web.xml" /> <fileset dir="${web}" includes="**/*.*" /> <!-- Create war file and place in ear directory --> <jar jarfile="${earDir}/${warFile}" basedir="${web}" /> </target> <!-- Create the Ear File --> <target name="buildEar"> <fileset dir="${deploymentdescription}" includes="application.xml" /> <!-- Create ear file and place in ear directory --> <jar jarfile="${dirs.base}/${earFile}" basedir="${earDir}" /> </target> <target name="deploy"> <copy todir="${dir.deploy.folder}" overwrite="yes"> <fileset file="${dirs.base}/${earFile}" /> </copy> <echo message="deployed" /> </target> </project>
- This is simple project where we are creating EAR file and deploy on the JBoss server (Version: 5.1.0). To create ear file: Right click build.xml –> Run As –> Ant Build you will see below output on console:
As you see above EARDeployment.ear got created inside JBoss deploy folder. Now start your JBoss server you will see below welcome page:
Download Project: EARDeployment
For more information about EAR deployment on JBoss please refer this JBoss link