Jeremy Stein - Brain

« »

Simple build.xml file for Java web application

For future reference, here’s the build.xml for a simple webapp:

<project name="NAME_OF_PROJECT" default="compile" basedir=".">
  <description>
    DESCRIPTION OF PROJECT
  </description>

  <!--
    build.properties should define:
    J2EE_LIBRARY_PATH - generally just points to the tomcat common/lib
    BUILD_PATH - where to build files (optional)
  -->
  <property file="build.properties"/>
  <property name="BUILD_PATH" location="build"/>

  <target name="compile" description="compile the source">
    <mkdir dir="${BUILD_PATH}"/>
    <copy todir="${BUILD_PATH}/webapp">
      <fileset dir="web" />
    </copy>
    <mkdir dir="${BUILD_PATH}/webapp/WEB-INF/lib"/>
    <copy todir="${BUILD_PATH}/webapp/WEB-INF/lib">
      <fileset dir="lib" excludes="**/*.zip"/>
    </copy>
    <mkdir dir="${BUILD_PATH}/webapp/WEB-INF/classes"/>
    <javac srcdir="src" destdir="${BUILD_PATH}/webapp/WEB-INF/classes" debug="true" debuglevel="lines,vars,source" source="1.5" target="1.5">
      <classpath>
        <fileset dir="lib" />
        <fileset dir="${J2EE_LIBRARY_PATH}" />
      </classpath>
      <include name="**/*.java"/>
    </javac>
    <copy todir="${BUILD_PATH}/webapp/WEB-INF/classes">
      <fileset dir="src" excludes="**/*.java"/>
    </copy>
  </target>

  <target name="dist" depends="compile" description="generate the distribution">
    <zip destfile="${BUILD_PATH}/NAME_OF_PROJECT.war" basedir="${BUILD_PATH}/webapp" />
  </target>

  <target name="clean" description="remove all generated files">
    <delete includeemptydirs="true">
      <fileset dir="${BUILD_PATH}" includes="*/**"/>
    </delete>
  </target>
</project>

August 2, 2012 No Comments.

No Comments

Be the first to comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Why ask?

« »