Andre Broers’ personal blog

October 9, 2007

Java JSF sample with my own build.xml script

Filed under: glassfish, j2ee, java, jsf — Tags: — broersa @ 11:09 am

I’m trying to get some grip on j2ee directory structures. I use the j2ee 5 tutorial.

I think the following tree is following the standard:

broersa@debian:~/jsf$ tree
.
|– build
| |– WEB-INF
| | |– classes
| | | `– guessNumber
| | | |– ApplicationMessages.properties
| | | `– UserNumberBean.class
| | |– faces-config.xml
| | |– sun-web.xml
| | `– web.xml
| |– greeting.jsp
| |– index.jsp
| |– response.jsp
| `– wave.med.gif
|– build.xml
|– jsf.war
|– jsf.war.txt
|– jsf.war.xml
|– src
| `– java
| `– guessNumber
| |– ApplicationMessages.properties
| `– UserNumberBean.java
`– web
|– WEB-INF
| |– faces-config.xml
| |– sun-web.xml
| `– web.xml
|– greeting.jsp
|– index.jsp
|– response.jsp
`– wave.med.gif

9 directories, 22 files
broersa@debian:~/jsf$
I wrote my own build.xml script that is plain simple to build the application:

<project name=”jsf” default=”build” basedir=”.”>
<description>
A simple build script.
</description>
<!– set global properties for this build –>
<!– change glassfish.home to point to appropriate location –>
<property name=”glassfish.home” location=”/home/broersa/glassfish”/>
<property name=”build” location=”build”/>

<target name=”init”>

<!– Create the build directory structure –>
<mkdir dir=”${build}/WEB-INF/classes”/>
</target>

<target name=”build” depends=”init”
description=”compile the entity beans and prepare a PU jar file.” >
<javac classpath=”${glassfish.home}/lib/javaee.jar”
srcdir=”src/java”
destdir=”${build}/WEB-INF/classes”/>
<copy file=”web/WEB-INF/web.xml” todir=”${build}/WEB-INF”/>
<copy file=”web/WEB-INF/sun-web.xml” todir=”${build}/WEB-INF”/>
<copy file=”web/WEB-INF/faces-config.xml” todir=”${build}/WEB-INF”/>
<copy todir=”${build}/WEB-INF/classes”>
<fileset dir=”src/java”>
<include name=”**/*.properties”/>
</fileset>
</copy>
<copy todir=”${build}”>
<fileset dir=”web”>
<include name=”**/*.jsp”/>
<include name=”**/*.gif”/>
</fileset>
</copy>
<jar destfile=”jsf.war” basedir=”${build}”/>
</target>

</project>

When I build the application and deploy to glassfish it works well.. Maybe there is a better (easier) way to copy all the files to the build location.

Blog at WordPress.com.