Use ant to config auto-deploy

ant manual http://ant.apache.org/manual/index.html

ant task list http://ant.apache.org/manual/tasklist.html

 

一个示例项目到ant编译与部署的配置:

项目代码:http://virtualearth.googlecode.com/files/Test_ANT.tar.gz

build.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
  <project name="Test" default="compile">
    <property name="build.dir" location="build_ant" />
    <property name="dist.dir" location="distribution"/>
    <property name="copy.dir" location="copyto"/>
   
    <target name="init">
        <mkdir dir="${build.dir}"></mkdir>
        <mkdir dir="${dist.dir}"></mkdir>
        <mkdir dir="${copy.dir}"></mkdir>
    </target>
   
    <target name="compile" depends="init">
        <javac srcdir="src" destdir="${build.dir}" debug="true" encoding="GBK">
            <classpath>
                <fileset dir="lib" includes="**/*.jar"></fileset>
            </classpath>       
        </javac>
        <copy todir="${build.dir}">
            <fileset dir="src" excludes="**/*.xml">                 
            </fileset>
        </copy>
    </target>
   
       
    <target name="dist" depends="compile">
        <mkdir dir="${dist.dir}/lib" />
        <jar jarfile="${dist.dir}/lib/Test.jar" basedir="${build.dir}" />
        <jar destfile="${dist.dir}/lib/Test2.jar">
            <fileset dir="${build.dir}" includes="**/*.class"></fileset>
            <fileset dir="src" excludes="**/*.java"></fileset>
            <manifest>
                <attribute name="Main-Class" value="Compile"></attribute>
                <attribute name="Class-Path" value="."/>
            </manifest>
            <zipgroupfileset dir="lib" includes="**/*.jar"/>       
        </jar>            
        <copy todir="${copy.dir}" includeemptydirs="false">
            <fileset dir="${dist.dir}"></fileset>       
        </copy>   
        <copy file="${dist.dir}/lib/Test.jar" tofile="Test-copy.jar"></copy>
    </target>

   
    <target name="clean" description="clear all things">
        <delete dir="${build.dir}"></delete>
        <delete dir="${dist.dir}"></delete>   
        <delete dir="${copy.dir}"></delete>   
        <delete dir="." includes="*.jar"></delete>   
    </target>
   
    </project>

posted @ 2011-01-19 22:49  白辉  阅读(308)  评论(0编辑  收藏  举报