很早就听说了apache 的这个开源工具,听人说配置繁琐,功能一般,一直没兴趣尝试,因为现在着迷eclipse ide,里面内置了ant,爱屋及乌吧,我想以eclipse的名气和品质,ant也是很好用的吧
1,先下载一个ant1.6,不会http://ant.apache.org最近上不去了,可以到网上找一下本地下载
2 apache-ant-1.6.2-bin.zip解压 有一个bib目录 把windows下的path指到这里
3.cmd进入控制台,输入ant -h 回车 看到帮助信息
4.在当前目录下建一个test.java文件
5 建一个build.xml文件
<project name="myproject" default="dist" basedir=".">
<!-- set global properties for this build -->
<property name="src" value="."/>
<property name="build" value="build"/>
<property name="dist" value="dist"/>
<target name="init">
<!-- create the time stamp -->
<tstamp/>
<!-- create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init">
<!-- compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile">
<!-- create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- put everything in ${build} into the myproject-${dstamp}.jar file -->
<jar jarfile="${dist}/lib/myproject-${dstamp}.jar" basedir="${build}"/>
</target>
<target name="clean">
<!-- delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
6.然后 ant 回车,成功了
从编译到打成jar包,一气合成,真爽!
然后进入eclipse ,对以前的项目小用了一下,真方便,再也不用修改文件后每次打开winrar,ctrl+c ctrl+v了
那个build.xml文件是看别人的,里面有些门道,继续研究中。。。
参考文章:
http://www.matrix.org.cn/resource/article/0/518.html
闽公网安备 35060202000074号