ANT Build.xml example

ANT Build.xml example
<?xml version="1.0" encoding="GB2312" ?>
<!--
    ============================ ==============================================
      hello-ant project, Learn the build file of the ant tool.

      Refer to the build.xml of jakarta-ant-1.6alpha of ant

      Copyright (c) 2002 The Neusoft Software Foundation. All rights
      reserved.

    ================ ===================================================== =====
-->

<!-- The
    document structure is:
    <project>
        <property/> Definition of global variables
        <property/>...

        <target name="1"> Task group (tasks)
            <javac> </javac> A javac task
            ...
            <oneTask></ontTask> an other task
        </target>

        <target name="2">
            <javac></javac>
            ...
            <oneTask></ontTask>
        </target>
    </project>

    project representative A project,
    default: run to a target (task group) named "dist"
    basedir: base path.
-->
<project default="dist" basedir=".">

<!--
    =============================== ====================================================================================================================================================================================================================
      _
      _ Yeah, names are all defined here as global variables
      Example: define
          <property name="a" value="


      现在:b=="hello/b"
    ===================================================================
-->

    <!--主要的系统环境属性-->
    <property environment="env"/><!--取window,unix...的环境变量-->
    <property name="java.home" value="${env.JAVA_HOME}"/>
    <property name="ant.home"  value="${env.ANT_HOME}"/>

    <!--主要的app环境属性-->
    <property name="app.name"      value="hello-ant"/>
    <property name="app.jar"       value="${app.name}.jar"/>
    <property name="app.copyright" value=" Copyright (c) 2002 The Neusoft Software Foundation.  All rights reserved."/>


    <!--app中src的属性-->
    <property name="src.dir"    value="src" />
    <property name="src.main"   value="${src.dir}/main"/>
    <property name="src.script" value="${src.dir}/script"/>

    <!--app用到的lib-->
    <property name="lib.dir" value="lib"/>

    <!--app的build目录中-->
    <property name="build.dir"      value="build" />
    <property name="build.classes"  value="${build.dir}/classes"/>
    <property name="build.docs"     value="${build.dir}/docs"/>
    <property name="build.docs.api" value="${build.docs}/api"/>
    <property name="build.lib"      value="${build.dir}/lib"/>

    <!--app的dist (distribution) 目录中-->
    <property name="dist.dir"      value="dist"/>
    <property name="dist.bin"      value="${dist.dir}/bin"/>
    <property name="dist.docs" value="${dist.dir}/docs"/>
    <property name="dist.lib" value="${dist.dir}/lib"/>

    <!-- In the app's docs directory -->
    <property name="docs.dir" value="docs"/>

    <!--
    After defining a set of paths, the set of paths can be reused by id, for example:
    <javac srcdir="src/ main" destdir="build/classes">
            <classpath refid="classpath"/>
    </javac>
    -->
    <path id="classpath">
        <!--This project has only one java, and classpath is not used, here Just an example -->
        <pathelement location="${build.classes}"/>
        <pathelement path=" ${java.home}/lib/tools.jar"/>
    </path>

<!--
    ===================================================== ================
      init Prepare the directory (File Tasks)
      The main directory structure is usually unchanged, and they are generated together
    =========== ===================================================== =====
-->
    <target name="init">
        <!--Clear previous directory-->
        <delete dir="${build.dir}" failonerror="false" />
        <delete dir=" ${dist.dir}" failonerror="false"/>

        <!--Prepare directory-->
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.classes}"/ >
        <mkdir dir="${build.docs}"/>
        <mkdir dir="${build.docs.api}"/>
        <mkdir dir="${build.lib}"/>

        <mkdir dir="${dist.dir}"/>
        <mkdir dir="${dist.bin}"/>
        <mkdir dir="${dist.lib}"/>

    </target>

<!--
    ===================================================================
      Build the code (Compile Tasks,File Tasks)
    ===================================================================
-->
    <target name="build" depends="init">
        <!--编译-->
        <javac srcdir="${src.main}" destdir="${build.classes}">
            <classpath refid="classpath"/>
        </javac>
    </target>

<!--       Archive Tasks
    =================================================== ====================

      Create the project jars: xxx1.jar and xxx2.jar
    ===================================================================
-->
   <target name="jars" depends="build">
        <jar basedir="${build.classes}" jarfile="${build.lib}/${app.jar}"/>
    </target>

<!--
     ===================================================================
       Creates the API documentation
     ===================================================================
-->
    <target name="javadocs"
            depends="jars"
            description="--> creates the API documentation">
        <!--copy docs 手册... -->
        <copy todir="${build.docs}">
            <fileset dir="${docs.dir}"/>
        </copy>

        <javadoc packagenames="hello.ant.*"
                 sourcepath="${src.main}"
                 defaultexcludes="yes"
                 destdir="${build.docs.api}"
                 author="true"
                 version="true"
                 use="true"
                 windowtitle="Docs API">
             <doctitle><![CDATA[<h1>hello ant Docs API</h1>]]></doctitle>
             <bottom><![CDATA[<i>${app.copyright}</i>]]></bottom>
             <tag name="todo" scope="all" description="To do:" />
         </javadoc>
    </target>

<!--
     ===================================================== ================
       Create the distribution that can run (Archive Tasks)
       is mainly to copy the copy from each directory
     =========== ===================================================== ======
-->
   <target name="dist" depends="javadocs">
        <!--copy bin executable file-->
        <copy todir="${dist.bin}">
            <fileset dir= "${src.script}/"/>
        </copy>
        <copy todir="${dist.docs}">
            <fileset dir="${build.docs}/"/>
        </copy>
        <!- - copy lib file -->
        <copy todir=" ${dist.lib}">
            <fileset dir="${build.lib}/"/>
        </copy>

    </target>
<!--
     ======================================= ============================
      Cleans everything (File Tasks)
      For example, you can delete the files in the build, leave it to you to play
     == ===================================================== ==============
-->

</project>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326928106&siteId=291194637
ANT
ANT