用Ant打包Jar文件(包含lib)
<projectdefault="jar"name="Acid">
<!--工程目录结构
project
|-bin
|-src
|-lib
|-out
|-build.xml
-->
<propertyname="lib.dir"value="lib"/>
<propertyname="src.dir"value="src"/>
<propertyname="classes.dir"value="bin"/>
<propertyname="output.dir"value="out"/>
<propertyname="jarname"value="Test.jar"/>
<propertyname="mainclass"value="com.biao.Test"/>
<!--第三方jar包的路径-->
<pathid="lib-classpath">
<filesetdir="${lib.dir}">
<includename="**/*.jar"/>
</fileset>
</path>
<!--1.初始化工作,如创建目录等-->
<targetname="init">
<mkdirdir="${classes.dir}"/>
<mkdirdir="${output.dir}"/>
</target>
<!--2.编译-->
<targetname="compile"depends="init">
<javacsrcdir="${src.dir}"destdir="${classes.dir}">
<compilerargline="-encodingUTF-8"/>
<classpathrefid="lib-classpath"/>
</javac>
</target>
<!--3.打包jar文件-->
<targetname="jar"depends="compile">
<copytodir="${output.dir}/lib">
<filesetdir="${lib.dir}"/>
</copy>
<!--Createapropertycontainingall.jarfiles,
prefixlib/,andseperatedwithaspace-->
<pathconvertproperty="mf.classpath"pathsep="">
<mapper>
<chainedmapper>
<!--jar包文件只留文件名,去掉目录信息-->
<flattenmapper/>
<!--addlib/prefix-->
<globmapperfrom="*"to="lib/*"/>
</chainedmapper>
</mapper>
<pathrefid="lib-classpath"/>
</pathconvert>
<!--jar文件的输出路径-->
<jardestfile="${output.dir}/${jarname}"basedir="${classes.dir}">
<manifest>
<attributename="Main-class"value="${mainclass}"/>
<attributename="Class-Path"value="${mf.classpath}"/>
</manifest>
</jar>
</target>
</project>