Ant构建
今天研究了下Ant.做了一个小例子![]()
首先下载Ant包,并且设置ANT_HONE环境变量。
项目结构目录如下:
test
|--src
|
|--install
|-archive
|-classes
|-dist
|-temp
|-build.xml
|-build.bat
build.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<project default="archive" name="TestAnt">
<property name="rootDir" location=".."/>
<property name="srcDir" location="../src"/>
<property name="classesDir" location="classes"/>
<property name="distDir" location="dist"/>
<property name="archiveDir" location="archive"/>
<property name="tempDir" location="temp"/>
<property name="ProjectName" value="TEST"/>
<!-- 初始化文件夹 -->
<target name="init" depends="clean">
<mkdir dir="${classesDir}" />
<mkdir dir="${distDir}" />
<mkdir dir="${archiveDir}" />
<mkdir dir="${tempDir}" />
</target>
<!-- 编译 -->
<target name="compile" depends="init">
<javac srcdir="${srcDir}" destdir="${classesDir}"/>
</target>
<!-- 打jar包 -->
<target name="mkJar" depends="compile">
<jar destfile="${distDir}/TEST.jar" basedir="${classesDir}"/>
</target>
<!-- 归档 -->
<target name="archive" depends="mkJar">
<!-- 运行包 -->
<zip destfile="${basedir}/archive/${ProjectName}_RUN_${build.date}.zip" basedir="${distDir}" />
<!-- 源码包 -->
<copy todir="${tempDir}/test">
<fileset dir="${rootDir}">
<include name="**"/>
<exclude name="install/**"/>
</fileset>
</copy>
<copy todir="${tempDir}/test/install" file="build.xml"/>
<zip destfile="${basedir}/archive/${ProjectName}_SRC_${build.date}.zip" basedir="${tempDir}" />
</target>
<!-- 清理文件夹 -->
<target name="clean">
<delete dir="${classesDir}"/>
<delete dir="${distDir}"/>
<delete dir="${archiveDir}" />
<delete dir="${tempDir}" />
</target>
<!-- 日期格式化 -->
<tstamp>
<format property="build.date" pattern="yyyyMMdd" />
</tstamp>
</project>
build.bat代码如下
@echo off
color 0A
echo ===============================================================================
echo .
echo Build Tool V1.0
echo .
echo ===============================================================================
echo build starting...
call %ANT_HOME%\bin\ant.bat -f build.xml
echo build end.
explorer archive
pause