其使用方法極為簡單,完整的操作流程可參考下列說明:
1. 開啟您的Eclipse IDE,建立一個TestProject的專案之後,於src/jcode/test套件目錄底下
新增HelloTest類別且於程式進入點的main()函式,加入以下的一段程式代碼:
public static void main(String[] args) {
|
2. 把滑鼠指標移至TestProject的圖示,然後點擊滑鼠右鍵,出現上下文選單(context menu)點取Export項目,
畫面帶出如下圖的"Export"對話方塊,選擇"Ant Buildfiles"圖示,來產出TestProject的build.xml文件檔:
3. 打開build.xml文檔,並且對該文件進行局部性的修改,其修改過的程式代碼以紅色粗體字表示。
<?xml
version="1.0" encoding="UTF-8"
standalone="no"?>
<project basedir="." default="build" name="TestProject">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../eclipse-sdk-helios"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<property name="dist" location="dist"/>
<path id="TestProject.classpath">
<pathelement location="bin"/>
<pathelement location="../../../jar-lib/ojdbc14.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<!--target depends="build-subprojects,build-project"
name="build"/-->
<target depends="dist" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}:
${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="TestProject.classpath"/>
</javac>
</target>
<target name="dist" depends="build-subprojects,build-project" description="generate
the distribution" >
<!-- 創建放置jar檔目錄 -->
<mkdir dir="${dist}/lib"/>
<!-- 把build目錄內的所有檔案結構打包成一個TestProject.jar檔
-->
<jar jarfile="${dist}/lib/${ant.project.name}.jar" basedir="bin"/>
</target>
<target description="Build
all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy
Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile
project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
</project>
4. 將滑鼠指標移動到build.xml圖示,單點滑鼠右鍵後選取"Run As -> 1 Ant Build"項目執行,會於"Console"輸出Ant的腳本代碼:
Buildfile: D:\works\TestProject\build.xml
build-subprojects:
init:
build-project:
[echo] TestProject:
D:\works\TestProject\build.xml
dist:
[mkdir] Created dir:
D:\works\TestProject\dist\lib
[jar] Building jar: D:\works\TestProject\dist\lib\TestProject.jar
build:
BUILD SUCCESSFUL
Total time: 526 milliseconds
我最喜歡的工具是CodelobsterIDE
回覆刪除