将bin下的class文件打成jar包,并在结果jar包中列出class-path,相应的包外面的lib目录中包括所有的jar文件
<?xml version="1.0" encoding="GBK"?>
<project basedir="." name="fbcisthread" default="jarfile">
<!--basedir 可设为任何目录名,设为.代表build.xml文件所有的目录-->
<property name="lib.dir" value="lib"/>
<property name="jar.app.name" value="fbcisthread.jar"/>
<property name="classpath.first" value="./lib/"/>
<property name="mf.main-class" value="gov.customs.thread.MainThread"/>
<property name="mf.created-by" value="eclink developer"/>
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="jarfile">
<!-- Convert project class path to string property -->
<pathconvert property="mf.classpath" pathsep=" ./lib/">
<path refid="project.classpath" />
<flattenmapper />
</pathconvert>
<jar jarfile="${jar.app.name}" basedir="bin" >
<include name="**/*.class"/>
<manifest>
<attribute name="Created-By" value="${mf.created-by}" />
<attribute name="Main-Class" value="${mf.main-class}" />
<attribute name="Class-Path" value="${classpath.first}${mf.classpath}" />
</manifest>
</jar>
</target>
</project>
下面比上面更进一步加入了编译内容:
<?xml version="1.0" encoding="GBK"?>
<project basedir="." name="fbcisthread" default="jarfile">
<!--basedir 可设为任何目录名,设为.代表build.xml文件所有的目录-->
<property name="lib.dir" value="lib"/>
<property name="bin.dir" value="bin"/>
<property name="jar.app.name" value="fbcisthread.jar"/>
<property name="classpath.first" value="./lib/"/>
<property name="mf.main-class" value="gov.customs.thread.MainThread"/>
<property name="mf.created-by" value="eclink developer"/>
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<delete dir="${bin.dir}"/>
<mkdir dir="${bin.dir}"> </mkdir>
</target>
<target name="compile" depends="init">
<javac destdir="${bin.dir}" srcdir="com:gov">
<classpath refid="project.classpath"/>
</javac>
</target>
<target name="jarfile" depends="compile">
<!-- Convert project class path to string property -->
<pathconvert property="mf.classpath" pathsep=" ./lib/">
<path refid="project.classpath" />
<flattenmapper />
</pathconvert>
<jar jarfile="${jar.app.name}" basedir="${bin.dir}" >
<include name="**/*.class"/>
<manifest>
<attribute name="Created-By" value="${mf.created-by}" />
<attribute name="Main-Class" value="${mf.main-class}" />
<attribute name="Class-Path" value="${classpath.first}${mf.classpath}" />
</manifest>
</jar>
</target>
</project>
下载ANT后运行以下脚本run.bat:
set ANT_HOME=C:\apache-ant-1.8.1
set JAVA_HOME=C:\Java\jdk1.6.0_14
set path=%path%;%JAVA_HOME%\bin;%ANT_HOME%\bin
rem cmd/k ant clean
cmd/k ant -buildfile buildCompile.xml
buildCompile.xml文件即是ant的xml文件
或者使用ant jarfile (其中jarfile名为ant xml文件中的target名)