很早就聽說了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
|
新聞熱點
疑難解答