Apache Ant 初步体验(小记)

发表于:2007-06-22来源:作者:点击数: 标签:
很早就听说了apache 的这个 开源 工具,听人说配置繁琐,功能一般,一直没兴趣尝试,因为现在着迷Eclipse IDE,里面内置了ant,爱屋及乌吧,我想以Eclipse的名气和品质,ant也是很好用的吧 1,先下载一个ant1.6,不会Http://ant.apache.org最近上不去了,可以

   

很早就听说了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

原文转自:http://www.ltesting.net