龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

Apache Ant 初步体验(小记)

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
很早就听说了apache 的这个开源工具,听人说配置繁琐,功能一般,一直没爱好尝试,因为现在着迷Eclipse IDE,里面内置了ant,爱屋及乌吧,我想以Eclipse的名气和品质,ant也是很好用的吧

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


  
精彩图集

赞助商链接