Creating My First War Build
Building a war requires an understanding of some conventions. First every application server has a directory named webapps. Most likely your application will be found under this directory. Your application should take the following format.
webapps
GettingStarted
sayhello.jsp
WEB-INF
web.xml
ericp
helloWorld.java
- GettingStarted : is the name of the application, and a directory
- sayhello.jsp : the only jsp
- ericp : a directory or package of java files
- WEB-INF : configuration for my webapp, and a directory
- web.xml : a required configuration file
A war is a compressed file, which the application server will expand. We need to set up our war to create files and directory to match this set up. My war task in my build.xml file looks like this. I want to include java file, and exclude test classes and main classes. The classes task moves the java files into the correct location, under WEB-INF/classes.
<war destfile="${dist}/GettingStarted.war"
webxml="web.xml"
basedir="${src}">
<classes dir="${src}">
<patternset id="non.delivery.items">
<include name="**/*.java"/>
<exclude name="**/main.*"/>
<exclude name="**/test*"/>
</patternset>
</classes>
</war>
My source directory looks like this
src
ericp
helloWorld.java
testCasts.java
main.java
sayhello.jsp
My web.xml file looks like this, so easy!
<web-app id="/">
<class-loader>
<compiling-loader path="WEB-INF/classes" />
</class-loader>
</web-app>