ant的build.xml,引入第三方包

ant的build.xml,引入第三方包

<?xml version="1.0" encoding="UTF-8"?>
<project default="run" name="Ts">
<!-- 工程目录结构
project
|-bin
|-src
|-lib
|-out
|-build.xml
-->
<property name="lib.dir" value="lib"/>
<property name="src.dir" value="src"/>
<property name="classes.dir" value="bin"/>

<property name="output.dir" value="out"/>
<property name="jarname" value="Test.jar"/>
<property name="mainclass" value="com.Test"/>

<!-- 第三方jar包的路径 -->
<path id="lib-classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>

<!-- 1. 初始化工作,如创建目录等 -->
<target name="init">
<mkdir dir="${classes.dir}"/>
<mkdir dir="${output.dir}"/>
</target>

<!-- 2. 编译 -->
<target name="compile" depends="init" >
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeAntRuntime="false">
<compilerarg line="-encoding UTF-8"/>
<classpath refid="lib-classpath"/>
</javac>
</target>

<!-- 3. 打包jar文件 -->
<target name="jar" depends="compile">
<copy todir="${output.dir}/lib">
<fileset dir="${lib.dir}"/>
</copy>

<!--Create a property containing all .jar files,
prefix lib/, and seperated with a space-->
<pathconvert property="mf.classpath" pathsep=" ">
<mapper>
<chainedmapper>
<!-- jar包文件只留文件名,去掉目录信息 -->
<flattenmapper/>
<!-- add lib/ prefix -->
<globmapper from="*" to="lib/*"/>
</chainedmapper>
</mapper>
<path refid="lib-classpath"/>
</pathconvert>

<!-- jar文件的输出路径 -->
<jar destfile="${output.dir}/${jarname}" basedir="${classes.dir}">
<manifest>
<attribute name="Main-class" value="${mainclass}"/>
<attribute name="Class-Path" value="${mf.classpath}"/>
</manifest>
</jar>
</target>
<!-- 4. 运行jar -->
<target name="run" depends="jar">
<java classname="${mainclass}" classpath="${output.dir}/${jarname}" />
<echo message="${output.dir}/${jarname}" />
</target>
<!-- 5. 清理 -->
<target name="clean">
<delete dir="${classes.dir}" />
<delete dir="${output.dir}" />
</target>
</project>

 

posted @ 2015-11-05 16:02  harry_ma  阅读(1611)  评论(0编辑  收藏  举报
 aa
    部分内容来自网络,如有异议,请联系我.     


      成绩来自坚持, 灵感来自激情。

                                                               感谢父母和亲朋好友的爱与支持!