| <project name="Generic Webapp" default="compile" basedir="."> |
| |
| <!-- |
| This is a generic build.xml file for Ant that can be used to develop |
| any web application that conforms to the following requirements: |
| |
| - Web sources appear in the directory specified by the "webapp.web" |
| property, in exactly the hierarchy to be present in the created |
| web application archive. |
| |
| - Java sources (if any) appear in the directory specified by the |
| "webapp.src" property, which will be compiled into the |
| "WEB-INF/classes" directory of the resulting web application. |
| |
| - You must specify a "servlet.jar" property that defines the path |
| of the servlet API classes you will compile against. |
| |
| - If you want to copy Struts libraries and TLD files to your web |
| application, set the "struts.libs" property to the pathname of a |
| directory containing struts.jar and the associated *.tld files. |
| |
| - If you want to copy additional JAR files into the WEB-INF/lib |
| directory of your web app, set the "webapp.libs" property to the |
| pathname of a directory containing the JAR files to be copied. |
| |
| --> |
| |
| |
| <!-- ========== Prerequisite Properties =================================== --> |
| |
| <!-- |
| These properties MUST be set on the "ant" command line, the "antrc" |
| properties file in your home directory, or from settings in a superior |
| build.xml script, if you wish to take advantage of the corresponding |
| functionality. |
| |
| compile.classpath The class path containing external |
| JAR files and directories required for |
| compiling this web application. Note |
| that struts.jar will automatically be |
| added if "struts.lib" is defined, and |
| dependent JAR files will be added if |
| "webapp.libs" is defined. |
| |
| build.home Base directory into which we are building |
| the Struts components. |
| |
| |
| servlet.jar MUST be set to the pathname of the |
| servlet API classes you wish to |
| compile against. |
| |
| struts.libs If specified, must be the pathname of a |
| directory from which "struts.jar" will be |
| copied to your WEB-INF/lib directory, and |
| from which all TLD files will be copied |
| to your WEB-INF directory. Also, the |
| struts.jar file will automatically be |
| added to your compile classpath. |
| |
| webapp.libs If specified, must be the pathname of a |
| directory from which all available |
| "*.jar" files are copied to the web |
| application's WEB-INF/lib directory. |
| Also, any JAR files found here will |
| automatically be added to your compile |
| classpath. |
| |
| webapp.name MUST be set to the base name of the web |
| application archive file that will be |
| created for this web application. |
| |
| webapp.suppress Set this property to an arbitrary value |
| (such as "true") if you do NOT want the |
| source code for your web application |
| copied to the WEB-INF/src directory. |
| |
| webapp.war If specified, overrides the default name |
| of the web application archive file to be |
| created for this webapp. Default value |
| is "struts-${webapp.name}.war". |
| |
| --> |
| |
| <property name="build.home" value="target" /> |
| <property name="servlet.jar" value="../jakarta-servletapi/lib/servlet.jar"/> |
| |
| |
| |
| <!-- ========== Initialization Properties ================================= --> |
| |
| |
| <!-- |
| These property values may optionally be overridden with property |
| settings from an "ant" command line, the "antrc" properties file |
| in your home directory, or from settings in a superior build.xml |
| script. |
| --> |
| |
| |
| |
| <!-- Should Java compilations set the debug compiler option? --> |
| <property name="compile.debug" value="true" /> |
| |
| <!-- Should Java compilations set the deprecation compiler option? --> |
| <property name="compile.deprecation" value="false" /> |
| |
| <!-- Should Java compilations set the optimize compiler option? --> |
| <property name="compile.optimize" value="true" /> |
| |
| <!-- The base directory for distribution targets --> |
| <property name="dist.home" value="dist" /> |
| |
| <!-- The source directory for Java compilations related to this webapp --> |
| <property name="webapp.src" value="src/${webapp.name}" /> |
| |
| <!-- The version number of this particular web application --> |
| <property name="webapp.version" value="1.0.1" /> |
| |
| <!-- The name of the web application archive file to be produced --> |
| <property name="webapp.war" value="${webapp.name}.war" /> |
| |
| <!-- The source directory for copying static web resources and files --> |
| <property name="webapp.web" value="web/${webapp.name}" /> |
| |
| |
| <!-- ========== Derived Properties ======================================== --> |
| |
| |
| <!-- |
| These property values are derived from values defined above, and |
| generally should NOT be overridden by command line settings |
| --> |
| |
| <!-- The target directory for building the packed web application --> |
| <property name="webapp.dist" value="${dist.home}/webapps" /> |
| |
| <!-- The target directory for building the unpacked web application --> |
| <property name="webapp.target" value="${build.home}/${webapp.name}" /> |
| |
| <!-- The class path used for compiling this library --> |
| <path id="classpath"> |
| <pathelement location="${jdbc20ext.jar}"/> |
| <pathelement location="${servlet.jar}"/> |
| <pathelement location="${struts.libs}/struts.jar"/> |
| <pathelement location="${webapp.libs}"/> |
| <pathelement path="${compile.classpath}"/> |
| </path> |
| |
| |
| <!-- ========== Executable Targets ======================================== --> |
| |
| |
| <!-- |
| The "init" target evaluates "available" expressions as necessary |
| to modify the behavior of this script. |
| --> |
| <target name="init"> |
| |
| <echo message="Processing webapp ${webapp.name}"/> |
| |
| <!-- Do we need to copy dependent libraries? --> |
| <available property="copy.libs" file="${webapp.libs}" /> |
| |
| <!-- Do we need to compile the Java sources for this web application? --> |
| <available property="webapp.compile" file="${webapp.src}" /> |
| |
| <!-- Should we copy Struts library and TLD files? --> |
| <available property="webapp.struts" file="${struts.libs}" /> |
| |
| </target> |
| |
| |
| <!-- |
| The "prepare" target creates a directory structure in the build target |
| area for the unpacked files associated with this web application |
| --> |
| <target name="prepare" depends="init" |
| description="Prepare target directory"> |
| <echo message="Processing webapp ${webapp.name}"/> |
| <mkdir dir="${webapp.target}" /> |
| <mkdir dir="${webapp.target}/WEB-INF" /> |
| <mkdir dir="${webapp.target}/WEB-INF/classes" /> |
| <mkdir dir="${webapp.target}" /> |
| </target> |
| |
| |
| <!-- |
| The "libs" target copies specified library JAR files (if any) from the |
| "${webapp.libs} directory into the WEB-INF/lib directory of this app. |
| --> |
| |
| <target name="libs" depends="prepare" if="copy.libs" |
| description="Copy dependent libraries"> |
| <echo message="Processing webapp ${webapp.name}"/> |
| <mkdir dir="${webapp.target}/WEB-INF/lib" /> |
| <copy todir="${webapp.target}/WEB-INF/lib"> |
| <fileset dir="${webapp.libs}" includes="*.jar"/> |
| </copy> |
| </target> |
| |
| |
| <!-- |
| The "source" target copies the Java source code of your web application |
| into the build target area, IF AND ONLY IF the "webapp.source" |
| property has been set to an arbitrary value. |
| --> |
| |
| <target name="source" depends="prepare" if="webapp.compile" |
| unless="webapp.suppress" |
| description="Copy Java sources"> |
| <echo message="Processing webapp ${webapp.name}"/> |
| <mkdir dir="${webapp.target}/WEB-INF/src"/> |
| <copy todir="${webapp.target}/WEB-INF/src"> |
| <fileset dir="${webapp.src}"/> |
| </copy> |
| </target> |
| |
| |
| <!-- |
| The "struts" target copies the Struts library JAR file and TLDs |
| into the build target area. |
| --> |
| <target name="struts" depends="prepare" if="webapp.struts" |
| description="Copy Struts library and TLD files"> |
| <echo message="Processing webapp ${webapp.name}"/> |
| <copy todir="${webapp.target}/WEB-INF"> |
| <fileset dir="${struts.libs}" includes="*.tld"/> |
| </copy> |
| <mkdir dir="${webapp.target}/WEB-INF/lib"/> |
| <copy todir="${webapp.target}/WEB-INF/lib"> |
| <fileset dir="${struts.libs}" includes="struts.jar"/> |
| </copy> |
| </target> |
| |
| |
| <!-- |
| The "static" target copies the static web resources portion of your |
| web application source into the build target area. |
| --> |
| <target name="static" depends="prepare,source,libs,struts" |
| description="Copy static files"> |
| <echo message="Processing webapp ${webapp.name}"/> |
| <copy todir="${webapp.target}"> |
| <fileset dir="${webapp.web}"/> |
| </copy> |
| </target> |
| |
| |
| <!-- |
| The "compile" target compiles the Java source code of your web |
| application, if and only if the specified source directory |
| actually exists. |
| --> |
| <target name="compile" depends="static" if="webapp.compile" |
| description="Compile Java sources"> |
| <echo message="Processing webapp ${webapp.name}"/> |
| <javac srcdir="${webapp.src}" |
| destdir="${webapp.target}/WEB-INF/classes" |
| debug="${compile.debug}" |
| deprecation="${compile.deprecation}" |
| optimize="${compile.optimize}"> |
| <classpath refid="classpath"/> |
| </javac> |
| <copy todir="${webapp.target}/WEB-INF/classes"> |
| <fileset dir="${webapp.src}"> |
| <exclude name="**/*.java"/> |
| </fileset> |
| </copy> |
| </target> |
| |
| |
| |
| <!-- |
| The "dist" target creates a web application archive containing |
| your completed web application, suitable for deployment on any |
| compatible servlet container. |
| --> |
| <target name="dist" depends="compile" |
| description="Create web application archive"> |
| <echo message="Processing webapp ${webapp.name}"/> |
| <jar jarfile="${webapp.dist}/${webapp.war}" |
| basedir="${webapp.target}"/> |
| </target> |
| |
| |
| <!-- |
| The "clean" task deletes any created directories that have resulted |
| from running any of the other targets in this script. |
| --> |
| |
| <target name="clean" |
| description="Clean build and distribution directories"> |
| <echo message="Processing webapp ${webapp.name}"/> |
| <delete dir="${webapp.target}" /> |
| <delete file="${webapp.dist}/${webapp.war}"/> |
| </target> |
| |
| |
| </project> |