Sometimes when a product is so 'all set' and working for millions of years, we tend to forget the basics, the foundations of starting from scratch, and start scratching all over the place.
So following are the basics to get well equipped 'quickly'.
- Its just a directory structure zipped up.
- A folder called 'webContent' should have a dir structure containing 'view' elements (JSP, HTML)
- A folder called 'WEB-INF' will have the web application descriptor file called web.xml.
<?xml version="1.0" encoding="UTF-8" ?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>anitestp1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app> - Whatever is inside WEB-INF\classes should be automatically be included by most servers in the classpath. It has the classes folder and the lib folder which holds the java classes and the required library files.
- Tip: For the jBPM example, I put in the entire processes folder in WEB-INF/classes for example app to locate the /processes/aniTestP1/processdefinition.xml file.
- Following is a simple way to package a WAR file with jakarta Ant. The file is called build.xml, although you could have a different name and use a command C:\{projectdir}> ant -f myfilename.xml
<?xml version="1.0" encoding="UTF-8" ?>
<project default="all" basedir=".">
<target name="init">
<property name="basedir" value="." />
<property name="projecthome" value="${basedir}" />
<property name="javaSrcHome" value="${projecthome}/src" />
<property name="webContent" value="${projecthome}/webcontent" />
<property name="classdir" value="${projecthome}/WEB-INF/classes" />
<property name="libdir" value="${projecthome}/WEB-INF/lib" />
<property name="libbase" value="F:/delme/jbpm-jpdl-3.2.1" />
</target>
<target name="references">
<copy todir="${libdir}">
<fileset dir="${libbase}" />
</copy>
</target>
<!-- Main target -->
<target name="all" depends="init,build" />
<!-- Compile Java Files and store in /build/src directory -->
<target name="build">
<javac srcdir="${javaSrcHome}" destdir="${classdir}" debug="true" includes="**/*.java" classpath="${libbase}/jbpm-jpdl.jar" />
</target>
<!-- Create the WAR File -->
<target name="buildWar" depends="init">
<property name="buildDir" value="${projecthome}/build" />
<property name="warDir" value="${projecthome}/build/war" />
<property name="warFile" value="aniTest.war" />
<delete dir="${warDir}" />
<mkdir dir="${warDir}" />
<mkdir dir="${warDir}/WEB-INF" />
<mkdir dir="${warDir}/WEB-INF/classes/processes" />
<copy todir="${warDir}/WEB-INF">
<fileset dir="${projecthome}/WEB-INF" includes="**/*" />
</copy>
<copy todir="${warDir}">
<fileset dir="${webContent}" includes="**/*.*" />
</copy>
<copy todir="${warDir}/WEB-INF/classes/processes">
<fileset dir="${projecthome}/processes" includes="**/*" />
</copy>
<jar jarfile="${buildDir}/${warFile}" basedir="${warDir}" />
<delete dir="${warDir}" />
</target>
</project> - Notice how the buildWar target composes the symphony of the WAR file. Accumulating classes/libraries from some place, some XML files from other place, the webContent from some place and the web.xml into the war file.
- A very good technique is to formulate the war file in a build directory under the project's root directory. Build it from there and then delete the temp directory. This helps build and keep versions of the production file if needed.
- For the jBPM example, I had take care of putting processdefinition.xml in classpath, including the jbpm-jpdl.jar file in the WEB-INF/lib, including the following files in the WEB-INF/classes folder log4j.properties, jbpm.mail.templates.xml, jbpm.cfg.xml, hibernate.cfg.xml (These are all default files created while creating a jBPM project in eclipse and eclipse build put these there after i configured the default output folder to be WEB-INF/classes and finally building the war file.
- Once the war file was build and had all the necessary components in it, simply copying it to the F:\delme\jbpm-jpdl-3.2.1\server\server\jbpm\deploy directory will deploy it on the running jBoss server.
Notes:
- The contextRoot is the name of the .war file. Once TODO out of this excersize is to be able to have a different war filename and contextroot.
Post a Comment