Using Ant for the Configuration


Of course, just putting the tags in the comment section doesn't do much until we combine it with Ant and XDoclet. In fact, we will need a specific task called webdoclet and one of its subtasks called deploymentdescriptor. There are a couple paths that you will need to know before looking at the build script. These are:

  • Location of the XDoclet install: on our test box it is /usr/local/xdoclet/lib

  • Location of the deploy directory of your application server: /usr/local/resin/webapps

  • Location of your application server's lib directory: /usr/localresin/lib

Here's an example task to handle the conversion of the deployment descriptor tags:

 <'?xml version="l.0" ?> <project name="webdoclet" default="deploy"> <path id="libpath"> <fileset dir="/usr/local/resin/lib"/> </path> <path id="xdocpath"> <path refid="libpath"> <fileset dir="/usr/local/xdoclet/lib"> <include name="*.jar"/> </fileset> </path> <target name= "init"> <mkdir dir="./tmp/war" /> <mkdir dIi-"./web/WEB-INF/cl asses" /> </target> <target name="compile"> <javac srcdir="./src" destdir="./web/WEB-INF/classes" debug="true" deprecation="true"> <classpath refid="libpath"/> </javac> </target> <target name="generateDD"> <taskdef name="webdoclet" classname="xdoclet. moduels.web.WebDocletTask" classpathref="xdocpath" <webdoclet destdir="./web/WEB -INF/classes"> <fileset dir="./src"> <include name="* */*Servlet.java" /> </fileset> <deploymentdescriptor servletspec="2.3" destdir="./web/WEB-INF" /> </webdoclet> <target> <target name="package" depends="init, compile, generateDD"> <war defile="Jtmp/war/example.war" webxml="./web/WEB-INF/web.xml"> <fileset dir="./web"> <exclude name="* */build.xml" /> <exclude name="**/*.bat" /> <exclude name="* */web.xml" /> <exclude name="**/*.java" /> <exclude name="**/*.class" /> </fileset> <lib dir="./web/WEB-INF/lib"/> <classes dir="./web/WEB-INF/classes"> <exclude name="* */*.Java"/> </classes> </war> </target> <target name="deploy" depends="package"> <copy file="./tmp/war/example. war" todir="/usr/local/resin/webapps" /> </target> 

So what have we done in this build script? First we needed to accomplish two tasks . The first was to generate the deployment descriptor using the <webdoclet> task. Since webdoclet isn't a common task with Ant, we needed to define it using the <taskdef> element. Next, we defined where XDoclet's library files can be found so that Ant will be able to find the class that actually implements webdoclet. Finally, we added the <webdoclet> task, which will process all files within the /src directory having Servlet.java as part of their filename. The resulting deployment descriptor will be placed in the directory ./web/WEB-INF.

After the deployment descriptor is created, the build script will compile the servlet, produce a WAR file, and deploy it to the webapps directory of the application server. Once Ant has finished with the processing of the files, you should have a successful build. At this point, you can browse to the application server and see the contents of your database displayed.




Professional Java Tools for Extreme Programming
Professional Java Tools for Extreme Programming: Ant, XDoclet, JUnit, Cactus, and Maven (Programmer to Programmer)
ISBN: 0764556177
EAN: 2147483647
Year: 2003
Pages: 228

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net