最近没事,研究了下ant。
用ant的目的就是编译,打包(jar包),自动生成帮助文档等。用ant首先要下载ant的安装包,完了系统的环境变量里面添加ant_home参数,path里添加ant/bin目录。如果是在eclipse里用的话就不需要了,只要工程目录下编辑一个build.xml就行,运行的时候点build.xml 右键---run as ---ant build,就可以运行了。
<?xml version="1.0" encoding="GB2312" ?>
<!-- 一个项目,可包含很多任务组(target) -->
<project default="main" basedir=".">
<property name="src" value="src"/>
<property name="build.classes" value="classes"/>
<property name="dist" value="build"/>
<property name="app.jar" value="anttest.jar"/>
<property name="app.name" value="anttest"/>
<property name="build.docs.api" value="docs"/>
<property name="build.lib" value="lib/rssservice.jar;lib/jdom.jar;lib/htmlparser.jar;lib/fmsware.jar;lib/baidusearch.jar;lib/servlet-api.jar;lib/jmmsc.jar;lib/dbconnectionpool.jar;lib/log4j-1.2.8.jar;lib/commmethod.jar;lib/umsSS.jar;lib/axis.jar;lib/jcmppapi30.jar;lib/jaxrpc.jar;lib/activation.jar;lib/mail.jar;lib/dom4j-1.5-rc1.jar;lib/jug-lgpl-2.0.0.zip;lib/smsapi.jar;"/>
<!-- 创建classes目录 -->
<target name="init">
<delete dir="${build.classes}" failοnerrοr="false" />
<mkdir dir="${build.classes}"/>
<delete dir="${build.docs.api}" failοnerrοr="false" />
<mkdir dir="${build.docs.api}"/>
</target>
<!-- 设置classpath -->
<path id="classpath">
<pathelement location="${build.classes}"/>
<pathelement path="${build.lib}"/>
</path>
<target name="main" depends="init">
<!-- 编译 -->
<javac srcdir="${src}" destdir="${build.classes}" debug="off" target="1.4" classpathref="classpath"/>
<!-- 执行 -->
<!-- 打包 -->
<jar jarfile="${app.jar}" basedir="${build.classes}" excludes="**/test/*,**/*.dep2,**/.dep*/*,**/*.di"/>
<!-- 生成API -->
<javadoc packagenames="*.*"
sourcepath="${src}"
defaultexcludes="yes"
destdir="${build.docs.api}"
author="true"
version="true"
use="true"
windowtitle="Docs API">
<classpath>
<pathelement path="${build.lib}"/>
<pathelement path="${build.classes}"/>
</classpath>
<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>
<!-- 清除类 -->
<!--delete dir="${build.classes}"/-->
</target>
</project>