Files
struts/apps/build.xml
T
2006-07-21 01:04:41 +00:00

297 lines
14 KiB
XML

<project name="struts2-webapps" default="help" basedir=".">
<property file="../build.properties" />
<target name="help">
<echo>
o To create a new webapp structure, simply run
ant new
o To build a webapp, simply run:
ant build -Dwebapp=XXX
... Where XXX is the name of the webapp you want to build.
After the build is finished, the fully-built war file can
be found in the dist directory. You may deploy this file
to any servlet container.
For example:
ant build -Dwebapp=sandbox
o To build a portlet webapp, simply run:
ant build-portlet
You can use the 'container' system property to target a specific container, e.g. '-Dcontainer=exo'.
Supported containers are exo, gridsphere, liferay-3.6.1, jboss-portal-2.0, jboss-portal-2.2 and jetspeed2.
For IBM WebSphere Portal 5.1 and Apache Pluto 1.0.1, no container property is required.
For example:
ant build-portlet -Dcontainer=jboss-portal-2.2
</echo>
</target>
<path id="cp">
<fileset dir="../lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="..">
<include name="struts2-*.jar" />
</fileset>
<!-- used so that we can build wars w/o building the whole distribution -->
<path path="../build/java" />
</path>
<macrodef name="compile">
<attribute name="srcdir" />
<attribute name="destdir" />
<attribute name="classpath" default="" />
<attribute name="classpathref" default="cp" />
<attribute name="excludes" default="" />
<attribute name="source" default="1.4" />
<attribute name="target" default="1.4" />
<sequential>
<mkdir dir="@{destdir}" />
<javac srcdir="@{srcdir}" destdir="@{destdir}" classpath="@{classpath}" classpathref="@{classpathref}" debug="on" source="@{source}" target="@{target}" />
<copy filtering="no" todir="@{destdir}">
<fileset dir="@{srcdir}">
<exclude name="**/*.java" />
<exclude name="**/package.html" />
</fileset>
</copy>
</sequential>
</macrodef>
<target name="build">
<condition property="hasWebAppLocation">
<isset property="webapplocation"/>
</condition>
<!-- prepare -->
<delete dir="${basedir}/tmp" />
<mkdir dir="${basedir}/tmp" />
<mkdir dir="${basedir}/dist" />
<antcall target="buildWithWebAppLocation" />
<antcall target="buildWithoutWebAppLocation" />
<!-- war up the app -->
<war file="${basedir}/dist/${webapp}.war" webxml="tmp/WEB-INF/web.xml">
<zipfileset dir="tmp" prefix="" />
<!-- only these configurations are needed for now. Also, these are probably more than
needed, but we're just picking a single set of jars that each webapp can use -->
<zipfileset dir="${basedir}/../lib/ajax" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/default" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/fileupload" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/sitemesh" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/portlet" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/jasperreports" prefix="WEB-INF/lib" excludes="commons-collections.jar" />
<zipfileset dir="${basedir}/../lib/spring" prefix="WEB-INF/lib" includes="*.jar" excludes="commons-logging.jar" />
<zipfileset dir="${basedir}/../lib/velocity" prefix="WEB-INF/lib" includes="velocity*.jar" />
<zipfileset dir="${basedir}/../lib/quickstart" prefix="WEB-INF/lib" includes="log4j.jar, commons-io.jar, commons-lang.jar, commons-collections.jar" />
<zipfileset dir="${basedir}/../lib/jfree" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../build" prefix="WEB-INF/lib" includes="${name}-${version}.jar" />
<zipfileset dir="${basedir}/.." prefix="WEB-INF/lib" includes="${name}-${version}.jar" />
</war>
</target>
<target name="buildWithoutWebAppLocation" unless="hasWebAppLocation">
<!-- copy over the webapp -->
<copy todir="${basedir}/tmp">
<fileset dir="${basedir}/${webapp}/src/main/webapp" />
</copy>
<!-- compile the sources -->
<mkdir dir="${basedir}/tmp/WEB-INF/classes" />
<compile srcdir="${basedir}/${webapp}/src/main/java" destdir="${basedir}/tmp/WEB-INF/classes" />
</target>
<target name="buildWithWebAppLocation" if="hasWebAppLocation">
<!-- copy over the webapp -->
<copy todir="${basedir}/tmp">
<fileset dir="${webapplocation}/${webapp}/src/main/webapp" />
</copy>
<!-- compile the sources -->
<mkdir dir="${basedir}/tmp/WEB-INF/classes" />
<compile srcdir="${webapplocation}/${webapp}/src/main/java" destdir="${basedir}/tmp/WEB-INF/classes" />
</target>
<target name="new" description="Create a new webapp project with the specified name and packages">
<echo level="info">
+=============================================================+
| -- Create a new web application -- |
+=============================================================+
</echo>
<echo/>
<!-- Prompt the user for input -->
<input message="Enter the name of your new application [myapp]?" addproperty="new.app.name"
defaultvalue="myapp" />
<input message="Enter the location of your new application [${basedir}]?" addproperty="new.app.location"
defaultvalue="${basedir}" />
<echo level="info">Creating '${new.app.location}/${new.app.name}' web application...</echo>
<copy todir="${new.app.location}/${new.app.name}">
<fileset dir="${basedir}/blank">
<exclude name="tmp/**"/>
<exclude name="build/**"/>
<include name="**"/>
<exclude name=".#**"/>
<exclude name="*.iml"/>
<exclude name="*.classpath"/>
<exclude name="CVS/**"/>
<exclude name="**/CVS"/>
</fileset>
</copy>
<!-- Commented out cause idea & eclipse file are missing -->
<!-- Copy the IDEA project file(s) -->
<!--copy file="blank/blank.iml" tofile="${new.app.name}/${new.app.name}.iml"/>
<replace dir="${new.app.name}" value="${new.app.name}" token="blank">
<include name="${new.app.name}.i*"/>
</replace -->
<!-- Copy the Eclipse project file(s) -->
<!--copy file="blank/.classpath" tofile="${new.app.name}/.classpath"/>
<replace file="${new.app.name}/.classpath" value="${basedir}/.." token="@STRUTS2_HOME@"/>
<replace file="${new.app.name}/.classpath" value="${version}" token="@STRUTS2_VERSION@"/>
<copy file="blank/.project" tofile="${new.app.name}/.project"/>
<replace file="${new.app.name}/.project" value="${new.app.name}" token="@PROJECT_NAME@"/ -->
<condition property="hasWebAppLocation">
<not>
<equals arg1="${new.app.location}" arg2="${basedir}" casesensitive="true" trim="true"/>
</not>
</condition>
<ant target="printConfigMessageWithWebAppLocation" />
<ant target="printConfigMessageWithoutWebAppLocation" />
</target>
<target name="printConfigMessageWithWebAppLocation" if="hasWebAppLocation">
<echo level="info">
+=============================================================================+
| -- Your Web Application was created successfully! -- |
| |
| Or if you have changed the default web app location: |
| > ant build -Dwebapp=${new.app.name} -Dwebapplocation=${new.app.location} |
| |
+=============================================================================+
</echo>
</target>
<target name="printConfigMessageWithoutWebAppLocation" unless="hasWebAppLocation">
<echo level="info">
+=============================================================================+
| -- Your Web Application was created successfully! -- |
| |
| Now you should be able to build your application with: |
| > ant build -Dwebapp=${new.app.name} |
| |
+=============================================================================+
</echo>
</target>
<target name="build-portlet" depends="prepare-portlet,prepare-portlet-deploy" description="Builds the portlet application. You can use the 'container' system property to target a specific container, e.g. '-Dcontainer=exo'. Supported containers are exo, gridsphere, jboss-portal-2.0, jboss-portal-2.2 and jetspeed2">
<!-- war up the app -->
<war file="${basedir}/dist/struts2-portlet.war" webxml="tmp/WEB-INF/web.xml">
<zipfileset dir="tmp" prefix="" />
<!-- only these configurations are needed for now. Also, these are probably more than
needed, but we're just picking a single set of jars that each webapp can use -->
<zipfileset dir="${basedir}/../lib/ajax" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/default" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/cewolf" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/fileupload" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/freemarker" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/sitemesh" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/spring" prefix="WEB-INF/lib" includes="*.jar" excludes="commons-logging.jar" />
<zipfileset dir="${basedir}/../lib/velocity" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../lib/quickstart" prefix="WEB-INF/lib" includes="log4j.jar, commons-lang.jar" />
<zipfileset dir="${basedir}/../lib/jfree" prefix="WEB-INF/lib" includes="*.jar" />
<zipfileset dir="${basedir}/../build" prefix="WEB-INF/lib" includes="${name}-${version}.jar" />
<zipfileset dir="${basedir}/.." prefix="WEB-INF/lib" includes="${name}-${version}.jar" />
</war>
</target>
<target name="prepare-portlet">
<property name="webapp" value="portlet" />
<!-- prepare -->
<delete dir="${basedir}/tmp" />
<mkdir dir="${basedir}/tmp" />
<mkdir dir="${basedir}/dist" />
<!-- copy over the webapp -->
<copy todir="${basedir}/tmp">
<fileset dir="${basedir}/${webapp}/src/webapp" />
</copy>
<!-- compile the sources -->
<mkdir dir="${basedir}/tmp/WEB-INF/classes" />
<compile srcdir="${basedir}/${webapp}/src/java" destdir="${basedir}/tmp/WEB-INF/classes" />
</target>
<target name="prepare-portlet-deploy" if="container">
<!-- Prepare descriptors and potential extra jars -->
<property name="deploy.src.dir" value="${basedir}/portlet/src/etc" />
<antcall target="prepare-${container}" />
</target>
<target name="prepare-exo">
<copy file="${deploy.src.dir}/exo/web.xml" tofile="tmp/WEB-INF/web.xml" overwrite="true" />
</target>
<target name="prepare-jboss-portal-2.2">
<copy todir="tmp/WEB-INF/">
<fileset dir="${deploy.src.dir}/jbossportal2.2">
<include name="*.*" />
</fileset>
</copy>
</target>
<target name="prepare-jboss-portal-2.0">
<copy todir="tmp/WEB-INF/" overwrite="true">
<fileset dir="${deploy.src.dir}/jbossportal2.0">
<include name="*.*" />
</fileset>
</copy>
</target>
<target name="prepare-jetspeed2">
<copy todir="tmp/WEB-INF/" overwrite="true">
<fileset dir="${deploy.src.dir}/jetspeed2">
<include name="*.*" />
</fileset>
</copy>
</target>
<target name="prepare-gridsphere">
<copy todir="tmp/WEB-INF/" overwrite="true">
<fileset dir="${deploy.src.dir}/gridsphere">
<include name="*.xml" />
<include name="*.txt" />
</fileset>
</copy>
<copy todir="tmp/WEB-INF/lib/" overwrite="true">
<fileset dir="${deploy.src.dir}/gridsphere">
<include name="*.jar" />
</fileset>
</copy>
</target>
<target name="prepare-liferay-3.6.1">
<copy todir="tmp/WEB-INF/" overwrite="true">
<fileset dir="${deploy.src.dir}/liferay3.6.1">
<include name="*.xml" />
</fileset>
</copy>
</target>
</project>