The Pet Store Case Study


The Web application for the pet store baseline is much like the one in the Hello World application. For simplicity and ease of development, most of the presentation tier is implemented in JSP. We added a nonsensical servlet just for demonstration purposes. Note that in the real world, we use Struts, a framework from Apache, and we have many Java classes to deploywe use Struts in several examples later in this book.

You may recall from the last case study that the main project buildfile for its build and clean target calls the webapplication subproject buildfile's clean and deploy targets respectively. The webapplication subproject buildfile's deploy target is defined as follows :

 <target name="deploy" depends="package">         <copy file="${dist}/${pet_war}" todir="${deploy_resin}" />         <copy file="${dist}/${pet_war}" todir="${deploy_tomcat}" />     </target> 

The deploy target copies the WAR file specified by ${pet_war} to both the Resin and Tomcat deployment directories. (Resin and Tomcat are both J2EE Web application servers.) The deploy target depends on the package target. The package target creates the WAR file that is deployed to Resin and Tomcat, which is defined as follows:

 <target name="package" depends="compile">         <mkdir dir="${meta}" />         <war warfile="${dist}/${pet_war}" webxml="${meta}/web.xml">             <!--                  Include the html and jsp files.                  Put the classes from the build into the classes directory                  of the war. Exclude web.xml file and WEB-INF directory.             /-->         <fileset dir="./public-html" >             <exclude name="WEB-INF" />             <exclude name="web.xml"/>           </fileset>           <classes dir="${build}" />         <lib dir="${lib}"  />         </war>    </target> 

As you will notice, the package target is much like the one in the Hello World Web application sample. The package target uses the war task to create a WAR file. The WAR file includes all the libraries in the lib (${lib})namely, the petmodel.jar file created in the model subproject. It also includes the web.xml Web application deployment descriptor using the "webxml" attribute. The following listing contains the complete Web application.

 <project name="webapplication" default="all" >     <target name="setProps" unless="setProps"                            description="setup the properites.">         <property name="outdir" value="/tmp/petstore" />      </target>          <target name="init" depends="setProps"                             description="initialize the properties.">      <tstamp/>      <property name="local_outdir" value="${outdir}/webapps" />      <property name="lib" value="${outdir}/lib" />      <property name="dist" value="${outdir}/dist" />      <property name="build" value="${local_outdir}/webclasses" />      <property name="meta" value="public-html/WEB-INF" />      <property name="deploy_resin" value="/resin/webapps" />      <property name="deploy_tomcat" value="/tomcat/webapps" />      <property name="appstub" value="pet" />      <property name="pet_war" value="${appstub}.war" />      <property name="build_lib" value="./../lib" />     </target>     <target name="clean_deploy" >         <delete file="${deploy_resin}/${pet_war}" />         <delete dir="${deploy_resin}/${appstub}" />         <delete file="${deploy_tomcat}/${pet_war}" />         <delete dir="${deploy_tomcat}/${appstub}" />     </target>     <target name="clean" depends="init,clean_deploy"                            description="clean up the output directories.">         <delete dir="${local_outdir}" />         <delete file="${dist}/${pet_war}" />     </target>          <target name="prepare" depends="init"                            description="prepare the output directory.">         <mkdir dir="${build}" />       <mkdir dir="${dist}" />     </target>     <target name="compile" depends="prepare"                            description="compile the Java source.">         <javac srcdir="./java" destdir="${build}">             <classpath >                 <fileset dir="${lib}">                     <include name="**/*.jar"/>                 </fileset>                          <fileset dir="${build_lib}">                     <include name="**/*.jar"/>                 </fileset>             </classpath>         </javac>     </target>     <target name="package" depends="compile">         <mkdir dir="${meta}" />         <war warfile="${dist}/${pet_war}" webxml="${meta}/web.xml">             <!--                  Include the html and jsp files.                  Put the classes from the build into the classes directory                  of the war. Exclude web.xml file and WEB-INF directory.             /-->         <fileset dir="./public-html" >             <exclude name="WEB-INF" />             <exclude name="web.xml"/>         </fileset>           <classes dir="${build}" />         <lib dir="${lib}"  />         </war>    </target>     <target name="deploy" depends="package">         <copy file="${dist}/${pet_war}" todir="${deploy_resin}" />         <copy file="${dist}/${pet_war}" todir="${deploy_tomcat}" />     </target>          <target name="all" depends="clean,deploy"                            description="perform all targets."/>  </project> 

As you can see, the standard targets are present in this buildfile as they are in the Hello World example, the model subproject, and the rest of the buildfiles in this book. This makes it easy to tell what the buildfiles are doing at a glance. You also may notice that the optional "description" attribute is set for each target. This also helps to document your targets and can be shown when running Ant.

The next case study will include the Test subproject buildfile using junit and the junitreport tasks . Then, it will add EJBeans support with a new subproject, and rerun the tests to ensure that the refactored CategorySystem still functions.




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