尝试这样:
<?xml version="1.0"?>
<project name="blah" basedir="." default="jar">
<target name="init">
<property name="build" value="./build" />
<property name="srcdir" value="./src" />
<property name="lib.dir" value="./lib" />
<property name="dist" value="./dist" />
<property name="docs" value="./docs" />
<property name="debug" value="true" />
<path id="project.class.path">
<pathelement path="${java.class.path}" />
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
</target>
<target name="compile" depends="init">
<mkdir dir="${build}" />
<javac debug="${debug}"
optimize="${optimize}"
destdir="${build}"
deprecation="${deprecation}"
source="1.6" target="1.6">
<src path="${srcdir}" />
<classpath refid="project.class.path" />
</javac>
</target>
<target name="jar" depends="compile">
<mkdir dir="${dist}" />
<jar destfile="${dist}/${ant.project.name}.jar">
<fileset dir="${build}">
<include name="com/blah/blah/*.class" />
</fileset>
</jar>
</target>
<target name="package" depends="compile, jar">
<jar destfile="${dist}/${ant.project.name}-release.jar" basedir="${build}" includes="**/*.*">
<manifest>
<attribute name="Main-Class" value="com.blah.blah.Main" />
</manifest>
<zipgroupfileset dir="${lib.dir}" includes="*.jar" />
<zipgroupfileset dir="${dist}" includes="${ant.project.name}.jar" />
</jar>
</target>
</project>
你会然后去:
ant package
要生成一个JAR文件与在的lib文件夹所有类。
也许这可能有所帮助:http://stackoverflow.com/questions/515428/clean-way-to-combine-multiple-jars-preferably-using-ant Fabrizio – 2011-05-17 07:10:07