Monday, November 21, 2011

Packing our web application into a war

As mentioned before, to deploy our web application, we need to pack it into a war file.

We do this with the Ant "war" task.

Update your Ant build.xml 'dist' target as shown below:

 <project name="HelloWorld" xmlns:ivy="antlib:org.apache.ivy.ant" >  

<target name="resolve" description="--> retrieve dependencies with ivy">
<ivy:retrieve />
</target>

<target name="init" depends="resolve">
<mkdir dir="classes"/>
<mkdir dir="target"/>
</target>

<target name="compile" depends="init">
<javac srcdir="." destdir="classes">
<classpath>
<pathelement location="lib/servlet-api-2.5.jar"/>
</classpath>
</javac>
</target>

<target name="dist" depends="compile">
<war destfile="target/HelloWorld.war" webxml="web.xml">
<classes dir="classes"/>
<lib dir="lib"/>
</war>
</target>
</project>


In the war task, we tell Ant to build a HeloWorld.war, and we tell it where to get the web.xml, the classes and the lib folders.

Ant will automatically create a WEB-INF directory from this information.

So now if you run the Ant:dist target, you will see a HelloWorld.war in your /target

No comments: