| Target | Description |
|---|
| setup | show webapp settings |
| gen | XDoclet web code generation |
| compile | compile source and copy resources |
| dist | package distribution file(s) |
| repo | add war to local Maven repository |
| clean | delete all non-source files |
| default | calls: clean, dist |
<?xml version="1.0" encoding="UTF-8"?>
<project name="webapp" default="default">
<description>
+ ==\_/============J=A=V=A=G=E=N===A=N=T===M=O=D=U=L=E=S================= +
+ \(_)/ +
+ -(_)- Web Application Core Module +
+ /(_)\ +
+ ======================================================================= +
+ Copyright (c) 2002-2005 Outsource Cafe, Inc. All rights reserved. +
+ ======================================================================= +
+
+ NOTE: webapp.xml went through a major refactoring in JAM 2.1
+
+ This is the core JAM module for webapp development. XDoclet code
+ generation, including Struts deployment descriptor handling is supported.
+ Resources and tlds are handled by POM settings, as are jar placement based
+ on the war.bundle and/or ear.bundle dependency tags. The optional
+ jar target places classes in a jar instead of in WEB-INF/classes. Setting
+ 'maven.type' to 'ear' will package your war within an ear distribution file.
+
+ Public targets:
+ setup, gen, compile, dist, repo, clean
+
+ Prerequisite imports:
+ props-global.xml, classpath.xml
+
+ Optional properties:
+ maven.type - set to 'war' or 'ear' to control distro type, default:'war'
+ build.classes.dir - redirect classes by setting this to '${basedir}/target/web/WEB-INF/classes'
+ webapp.context - context of web application, default: ${module.name}
+
+ TODO: Need to handle JSP compilation and config
+
+ developer: RichardEasterling@OutsourceCafe.com
+ ======================================================================= +
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ =J=A=M===========================================J=A=V=A=G=E=N=.=C=O=M= +
</description>
<property name="WEBAPP.PRESENT" value="true"></property>
<!-- =================================================================== -->
<!-- standard targets: -->
<!-- =================================================================== -->
<target name="setup" depends="init, webapp.settings" description="show webapp settings"></target>
<target name="gen" depends="init, webdoclet" description="XDoclet web code generation"></target>
<target name="compile" depends="gen, javac, resources, tlds, libs, slim.libs" description="compile source and copy resources"></target>
<target name="dist" depends="compile, manifest, jar, war, appxml, ear" description="package distribution file(s)"></target>
<target name="repo" depends="repo.init, dist, dist.install" description="add war to local Maven repository"></target>
<target name="clean" depends="clean.build, clean.dist" description="delete all non-source files"></target>
<target name="default" depends="clean, dist" description="calls: clean, dist"></target>
<!-- ===================================================================== -->
<!-- properties/datatypes specific to this module -->
<!-- ===================================================================== -->
<property name="maven.type" value="war"></property>
<property name="dist.jar.name" value="${module.name}-${module.version}.jar"></property>
<property name="dist.war.name" value="${module.name}-${module.version}.war"></property>
<property name="dist.name" value="${module.name}-${module.version}.${maven.type}"></property>
<property name="dist.file" location="${dist.dir}/${dist.name}"></property>
<property name="dist.jar.file" location="${build.web.webinf.dir}/lib/${dist.jar.name}"></property>
<property name="maven.folder" value="${maven.groupId}/${maven.type}s"></property>
<property name="pom.file.name" value="${module.name}-${module.version}.pom"></property>
<property name="pom.file" value="${basedir}/project.xml"></property>
<!-- ===================================================================== -->
<!-- logic to control distro type (war or ear) and WEB-INF/lib jar includes -->
<!-- ===================================================================== -->
<condition property="ear-distro" value="true">
<equals arg1="${maven.type}" arg2="ear"></equals>
</condition>
<condition property="slim-libs" value="true">
<isset property="ear-distro"></isset>
</condition>
<!-- ===================================================================== -->
<!-- adds war with context to application.xml -->
<!-- ===================================================================== -->
<property name="target.modules" value="<module><web><web-uri>${dist.war.name}</web-uri><context-root>${webapp.context}</context-root></web></module>"></property>
<echo>target.modules = ${target.modules}</echo>
<filterset id="appxml.module.filterset">
<filter token="TARGET-MODULE" value="${target.modules}"></filter>
</filterset>
<!-- ===================================================================== -->
<!-- Files to process by XDoclet -->
<!-- ===================================================================== -->
<patternset id="webdoclet.suffixes.id">
<include name="**/*Servlet.java"></include>
<include name="**/*Filter.java"></include>
<include name="**/*Tag.java"></include>
<include name="**/*Action.java"></include>
<include name="**/*Form.java"></include>
<include name="**/*Listener.java"></include>
</patternset>
<!-- ===================================================================== -->
<!-- sanity checks -->
<!-- ===================================================================== -->
<fail unless="CLASSPATH.PRESENT" message="classpath.xml must be imported before webapp.xml in build file. Regeneration of classpath.xml required when upgrading to JAM 2.1. Type: maven javagen:classpath"></fail>
<fail unless="PROPS-GLOBAL.PRESENT" message="props-global.xml must be imported before webapp.xml in build file."></fail>
<available property="jdk1.3+" classname="java.lang.StrictMath"></available>
<fail unless="jdk1.3+" message="Java versions prior to 1.3 not supported"></fail>
<target name="check">
<echo>DEPRICATED, checks are now in-lined</echo>
</target>
<!-- ===================================================================== -->
<!-- setup -->
<!-- ===================================================================== -->
<target name="webapp.settings">
<echo>
+ ==\_/=======J=A=V=A=G=E=N===A=N=T===M=O=D=U=L=E=S============ +
+ \(_)/ +
+ -(_)- WebApp Build Settings +
+ /(_)\ +
+ ============================================================= +
module.name/version = ${module.name} / ${module.version}
webapp.context = ${webapp.context}
dist.name = ${dist.name}
appserver.name/ver = ${appserver.name} / ${appserver.version}
appserver.deploy.dir = ${appserver.deploy.dir}
appserver.log.folder = ${appserver.log.folder}
jam.home = ${jam.home}
java.home/version = ${java.home} / ${ant.java.version}
debug/optimize = ${compiler.debug} / ${compiler.optimize}
ant.home = ${ant.home}
maven.home = ${maven.home}
maven.repo = ${maven.repo}
+ =J=A=M=================================J=A=V=A=G=E=N=.=C=O=M= +
</echo>
</target>
<!-- ===================================================================== -->
<!-- init -->
<!-- ===================================================================== -->
<target name="init">
<mkdir dir="${build.classes.dir}"></mkdir>
<mkdir dir="${src.java.dir}"></mkdir>
<mkdir dir="${gen.web.dir}"></mkdir>
<mkdir dir="${gen.java.dir}"></mkdir>
<mkdir dir="${xdoclet.build.web.dir}"></mkdir>
<taskdef name="webdoclet" classname="xdoclet.modules.web.WebDocletTask" classpathref="xdoclet.classpath"></taskdef>
<tstamp>
<format property="buildtime" pattern="yyyy-MM-dd'T'HH:mm:ss"></format>
</tstamp>
<echo file="${timestamp.path}" message="build.timestamp=${buildtime}"></echo>
</target>
<!-- =================================================================== -->
<!-- XDoclet webdoclet - defaults to deploymentdescriptor subtask call -->
<!-- =================================================================== -->
<macrodef name="webdoclet.macro">
<attribute name="destdir" default="${build.web.webinf.dir}"></attribute>
<attribute name="validatexml" default="${xdoclet.validatexml}"></attribute>
<attribute name="excludedtags" default="${xdoclet.excludedtags}"></attribute>
<attribute name="addedtags" default="@xdoclet-generated at ${TODAY},@copyright ${copyright},@author ${author},@version ${version}"></attribute>
<attribute name="sessiontimeout" default="${servlet.session.timeout}"></attribute>
<attribute name="mergedir" default="${xdoclet.merge.dir}"></attribute>
<attribute name="servletspec" default="${servlet.spec.version}"></attribute>
<attribute name="verbose" default="false"></attribute>
<attribute name="force" default="true"></attribute>
<attribute name="distributable" default="false"></attribute>
<element name="fileset.tag" optional="no"></element>
<element name="subtasks.tag" optional="yes"></element>
<!-- BEGIN DEPRICATED: the following tag elements are depricated, use subtasks.tag instead -->
<element name="predeployment.tag" optional="yes"></element>
<element name="postdeployment.tag" optional="yes"></element>
<element name="jsptaglib.tag" optional="yes"></element>
<element name="strutsconfigxml.tag" optional="yes"></element>
<element name="webxml.tag" optional="yes"></element>
<!-- END DEPRICATED-->
<sequential>
<echo>servlet.spec.version=${servlet.spec.version}</echo>
<echo>servletspec=@{servletspec}</echo>
<echo>mergedir=@{mergedir}</echo>
<webdoclet destdir="@{destdir}" addedtags="@{addedtags}" verbose="@{verbose}" mergedir="@{mergedir}" excludedtags="@{excludedtags}" force="@{force}">
<fileset.tag></fileset.tag>
<subtasks.tag></subtasks.tag>
<strutsconfigxml.tag></strutsconfigxml.tag>
<predeployment.tag></predeployment.tag>
<jsptaglib.tag></jsptaglib.tag>
<deploymentdescriptor servletspec="@{servletspec}" destdir="@{destdir}" validatexml="@{validatexml}" sessiontimeout="@{sessiontimeout}" distributable="@{distributable}"></deploymentdescriptor>
<postdeployment.tag></postdeployment.tag>
<webxml.tag></webxml.tag>
</webdoclet>
</sequential>
</macrodef>
<!-- =================================================================== -->
<!-- default webdoclet.macro use - override to include/exclude subtasks -->
<!-- =================================================================== -->
<target name="webdoclet" depends="webdoclet.uptodate" unless="webxml.uptodate">
<webdoclet.macro>
<fileset.tag>
<fileset dir="${gen.java.dir}">
<patternset refid="webdoclet.suffixes.id"></patternset>
</fileset>
<fileset dir="${src.java.dir}">
<patternset refid="webdoclet.suffixes.id"></patternset>
</fileset>
</fileset.tag>
<subtasks.tag>
<strutsconfigxml version="1.1" validatexml="${xdoclet.validatexml}" destdir="${build.web.webinf.dir}"></strutsconfigxml>
<weblogicwebxml destdir="${build.web.webinf.dir}" version="${appserver.version}" contextroot="${webapp.context}"></weblogicwebxml>
<jbosswebxml contextroot="${webapp.context}"></jbosswebxml>
</subtasks.tag>
</webdoclet.macro>
</target>
<!-- =================================================================== -->
<!-- copy web.xml replacing @JSPC_SERVLET_LISTING@ tag -->
<!-- ===================================================================
<target name="webxml.copy">
@JSPC_SERVLET_LISTING@
</target>
-->
<!-- =================================================================== -->
<!-- checks that all source files are uptodate for webdoclet -->
<!-- =================================================================== -->
<target name="webdoclet.uptodate">
<uptodate property="webxml.uptodate" targetfile="${build.web.webinf.dir}/web.xml">
<srcfiles dir="${src.java.dir}"></srcfiles>
<srcfiles dir="${gen.java.dir}"></srcfiles>
</uptodate>
<echo>webxml.uptodate=${webxml.uptodate}</echo>
</target>
<!-- =================================================================== -->
<!-- compiles the source code -->
<!-- =================================================================== -->
<target name="javac">
<javac destdir="${build.classes.dir}" target="${compiler.target}" source="${compiler.source}" classpathref="build.classpath" debug="${compiler.debug}" deprecation="${compiler.deprecation}" optimize="${compiler.optimize}" compiler="${compiler.type}" excludes="${compiler.excludes}">
<src path="${xdoclet.build.web.dir}"></src>
<src path="${src.java.dir}"></src>
<src path="${gen.java.dir}"></src>
<patternset refid="source.modifications.patternset"></patternset>
</javac>
</target>
<!-- ===================================================================== -->
<!-- copy log4j property file - THIS MAY BE A BIT SPECIALIZED TO BE HERE -->
<!-- Replaces @LOG-FOLDER@ tag with server-specific log folder location. -->
<!-- ===================================================================== -->
<target name="log4j">
<property name="log4j.config.file" location="${src.config.dir}/log4j-init.properties"></property>
<!-- copy log4j-init.properties from config folder -->
<mkdir dir="${src.config.dir}"></mkdir>
<mkdir dir="${build.web.webinf.dir}/classes"></mkdir>
<copy file="${log4j.config.file}" todir="${build.web.webinf.dir}/classes" overwrite="true">
<filterset>
<filter token="LOG-FOLDER" value="${appserver.log.folder}"></filter>
</filterset>
</copy>
</target>
<!-- ===================================================================== -->
<!-- libs - copy all dependencies -->
<!-- 'web.lib.fileset' is found in classpath.xml. -->
<!-- ===================================================================== -->
<target name="libs" unless="slim-libs">
<!-- copy contents of optional lib directory -->
<mkdir dir="${build.web.webinf.dir}/lib"></mkdir>
<copy todir="${build.web.webinf.dir}/lib" flatten="true">
<fileset refid="web.lib.fileset"></fileset>
<fileset dir="${basedir}" includes="${lib.folder}/*.jar"></fileset>
</copy>
</target>
<!-- ===================================================================== -->
<!-- slim libs - copy only dependencies that are not duplicated in ear -->
<!-- 'web.ear.lib.fileset' is found in classpath.xml. -->
<!-- ===================================================================== -->
<target name="slim.libs" if="slim-libs">
<!-- copy contents of optional lib directory -->
<mkdir dir="${build.web.webinf.dir}/lib"></mkdir>
<copy todir="${build.web.webinf.dir}/lib" flatten="true">
<fileset refid="web.ear.lib.fileset"></fileset>
<fileset dir="${basedir}" includes="${lib.folder}/*.jar"></fileset>
</copy>
</target>
<!-- ===================================================================== -->
<!-- the 'tlds' target copies tlds to WEB-INF/tld is found in in classpath.xml -->
<!-- ===================================================================== -->
<!-- ===================================================================== -->
<!-- build manifest for war file -->
<!-- ===================================================================== -->
<target name="manifest">
<mkdir dir="${build.web.dir}/META-INF"></mkdir>
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF">
<attribute name="Built-By" value="${user.email}"></attribute>
<attribute name="Built-On" value="${buildtime}"></attribute>
<!--attribute name="Main-Class" value="org.example.antbook.Search"/-->
</manifest>
</target>
<!-- ===================================================================== -->
<!-- Build jar file containing webapp classes. If this task is omitted, -->
<!-- classes will be included in the war under WEB-INF/classes. -->
<!-- ===================================================================== -->
<target name="jar">
<delete file="{dist.jar.file}" failonerror="false"></delete>
<mkdir dir="${build.web.webinf.dir}/lib"></mkdir>
<jar destfile="${dist.jar.file}" compress="true" update="false" manifest="${build.web.dir}/META-INF/MANIFEST.MF">
<fileset dir="${build.classes.dir}"></fileset>
</jar>
<property name="dist.jar.present" value="true"></property>
</target>
<!-- ===================================================================== -->
<!-- build the war file for web server deployment -->
<!-- ===================================================================== -->
<target name="war">
<delete file="${dist.dir}/${dist.war.name}" failonerror="false"></delete>
<mkdir dir="${dist.dir}"></mkdir>
<echo>dist.jar.present = ${dist.jar.present}, dist.jar.name = ${dist.jar.name}</echo>
<jar destfile="${dist.dir}/${dist.war.name}" compress="true" update="false" manifest="${build.web.dir}/META-INF/MANIFEST.MF">
<fileset dir="${build.web.dir}">
<exclude name="WEB-INF/classes/**" if="dist.jar.present"></exclude>
</fileset>
<fileset dir="${build.dir}" includes="${timestamp.filename}"></fileset>
</jar>
</target>
<!-- =================================================================== -->
<!-- find and copy application.xml or fail -->
<!-- =================================================================== -->
<target name="appxml" if="ear-distro">
<condition property="duplicate.appxmls">
<and>
<available file="${gen.metainf.dir}/application.xml"></available>
<available file="${src.metainf.dir}/application.xml"></available>
</and>
</condition>
<fail if="duplicate.appxmls" message="ERROR: Two application.xml files found in ${gen.metainf.dir} and ${src.metainf.dir}. Please remove one."></fail>
<mkdir dir="${build.metainf.dir}"></mkdir>
<copy file="${gen.metainf.dir}/application.xml" todir="${build.metainf.dir}" failonerror="false" overwrite="true">
<filterset refid="appxml.module.filterset"></filterset>
</copy>
<copy file="${src.metainf.dir}/application.xml" todir="${build.metainf.dir}" failonerror="false" overwrite="true">
<filterset refid="appxml.module.filterset"></filterset>
</copy>
<available property="appxml.found" file="${build.metainf.dir}/application.xml"></available>
<fail unless="appxml.found" message="ERROR: application.xml NOT FOUND in ${src.metainf.dir} or ${gen.metainf.dir}, run: maven jam:appxml-filter"></fail>
</target>
<!-- =================================================================== -->
<!-- package ear -->
<!-- =================================================================== -->
<target name="ear" if="ear-distro">
<delete file="${dist.file}"></delete>
<mkdir dir="${dist.dir}/${temp.folder}"></mkdir>
<copy todir="${dist.dir}/${temp.folder}">
<fileset refid="ear.lib.fileset"></fileset>
<mapper type="flatten"></mapper>
</copy>
<ear destfile="${dist.file}" appxml="${build.metainf.dir}/application.xml">
<fileset dir="${dist.dir}" includes="*.war,*.jar"></fileset>
<fileset dir="${dist.dir}/${temp.folder}"></fileset>
</ear>
<delete dir="${dist.dir}/${temp.folder}" failonerror="false"></delete>
</target>
<!-- ===================================================================== -->
<!-- Clean targets -->
<!-- ===================================================================== -->
<target name="clean.build">
<delete dir="${build.dir}"></delete>
</target>
<target name="clean.dist">
<delete dir="${dist.dir}" failonerror="false"></delete>
</target>
<!-- =================================================================== -->
<!-- repo.init - sets 'slim-libs' to 'true' to remove duplicate jars -->
<!-- =================================================================== -->
<target name="repo.init">
<property name="slim-libs" value="true"></property>
</target>
<!-- =================================================================== -->
<!-- installs war jar in Maven repository -->
<!-- =================================================================== -->
<target name="dist.install">
<mkdir dir="${maven.repo}/${maven.folder}"></mkdir>
<copy file="${dist.file}" todir="${maven.repo}/${maven.folder}"></copy>
<checksum fileext=".md5" file="${maven.repo}/${maven.folder}/${dist.name}" forceoverwrite="true"></checksum>
<mkdir dir="${maven.repo}/${maven.groupId}/poms"></mkdir>
<copy file="${pom.file}" tofile="${maven.repo}/${maven.groupId}/poms/${pom.file.name}"></copy>
</target>
</project>