关于ant的build.xml、version.properties、build.properties例子

build.xml
dist为开发环境,dist-Product为生产环境

<project name="teststrutsspring" basedir="." default="dist">
    <property file="build.properties" />
    <property file="version.properties" />
    <property name="src" location="src" />
    <property name="build" location="build" />
    <property name="dist" location="dist" />
    <property name="lib.dir" location="WebRoot/WEB-INF/lib" />
    <property name="web" location="WebRoot" />

    <target name="dist" description="Generate the distribution">
        <antcall target="clean" />
        <antcall target="init" />
        <antcall target="getVersion" />
        <antcall target="compile" />
        <antcall target="copyother" />
        <antcall target="jar" />
        <antcall target="jarclientapi" />
        <antcall target="war" />
    </target>

    <target name="dist-Product" description="Generate the Product">
        <antcall target="clean" />
        <antcall target="init" />
        <antcall target="getVersion" />
        <antcall target="compile" />
        <antcall target="copyother" />
        <antcall target="copy-product-env-config" />
        <antcall target="jar" />
        <antcall target="war" />
        <echo>Generate the product environment!</echo>
    </target>

    <target name="init">
        <!-- Create the time stamp -->
        <tstamp />
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${build}" />
        <mkdir dir="${dist}" />
    </target>

    <target name="clean" description="clean up">
        <!-- Delete the ${build} and ${dist} directory trees -->
        <delete dir="${build}" />
        <delete dir="${dist}" />
    </target>

    <target name="getVersion">
        <propertyfile file="version.properties" comment="This is Version File">
            <entry key="buildDate" type="date" value="now" pattern="yyyy-MM-dd HH:mm:ss" />
        </propertyfile>
        <property file="version.properties" />
        <copy todir="${build}">
            <fileset dir=".">
                <include name="version.properties" />
            </fileset>
        </copy>
    </target>

    <path id="all-libs">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <target name="compile" description="compile the source">
        <!-- Compile the java code from ${src} into ${build} -->
        <javac srcdir="${src}" destdir="${build}" encoding="UTF-8" nowarn="true" source="1.5">
            <classpath refid="all-libs" />
        </javac>
    </target>

    <target name="copyother">
        <copy todir="${build}">
            <fileset dir="${src}">
                <include name="**/**" />
                <exclude name="**/*.java" />
                <exclude name="*.properties" />
                <exclude name="*.xml" />
            </fileset>
        </copy>
        <copy todir="${dist}/${webname}">
            <fileset dir="${web}">
                <include name="**/*" />
                <exclude name="**/WEB-INF/classes/**" />
            </fileset>
        </copy>
        <copy todir="${dist}/${webname}/WEB-INF/classes">
            <fileset dir="${src}">
                <include name="*.properties" />
                <include name="*.xml" />
            </fileset>
        </copy>
    </target>

    <target name="jar" description="Generate the distribution">
        <jar jarfile="${dist}/${projectname}-${version}.jar" basedir="${build}" compress="true">
        </jar>
        <copy todir="${dist}/${webname}/WEB-INF/lib">
            <fileset dir="${dist}">
                <include name="${projectname}-${version}.jar" />
            </fileset>
        </copy>
    </target>

    <target name="jarclientapi" description="Generate the jar client api">
        <jar jarfile="${dist}/${clientapiname}-${version}.jar" compress="true">
            <fileset dir="${build}">
                <include name="**/*.class" />
            </fileset>
        </jar>
    </target>
    
    <target name="copy-product-env-config">
            <copy todir="${dist}/${webname}/WEB-INF/classes" overwrite="true">
                <fileset dir="ProductEnv-Config">
                    <include name="*.properties" />
                </fileset>
            </copy>
        </target>

    <target name="war">
        <war basedir="${dist}/${webname}" warfile="${dist}/${webname}.war" webxml="${dist}/${webname}/WEB-INF/web.xml" compress="false">
        </war>
    </target>
</project>



build.properties

projectname=teststrutsspring
webname=teststrutsspring
clientapiname=teststrutsspring-pojo


version.properties

#This is Version File
#Fri Sep 10 11:05:45 CST 2010
version=1.0.0
buildDate=2010-09-10 11\:05\:45

你可能感兴趣的:(java,xml,ant)