eclipse 雖然自帶了ant 插件,但在調試過程中只能調試到ant 腳本,而且準備classpath時不能引用某個工程,因此不能調試具體的java 代碼。有時候我們要對自定義的ant task進行調試,甚至有時候想對ant 源碼進行調試,ant插件是無法做到這一點。
由於ant是用java代碼編寫而成,並且有可執行的main函數,而事實上ant就是調用main函數來運行ant腳本的,因此我們可以用java application的形式來運行ant,方法如下:
1. 打開Debug Ddialog,新建一個任務,輸入任務名稱,選擇工程,選擇main class,這裏是org.apache.tools.ant.Main,注意要把ant 相關jar包導入工程中去。
2. 轉到Arguments tag,在Program arguments上寫上ant 腳本的運行參數,形式如下:
ant [options] [target [target2 [target3] ...]]
Options:
-help
|
print this message
|
-projecthelp
|
print project help information
|
-version
|
print the version information and exit
|
-diagnostics
|
print information that might be helpful to
diagnose or report problems.
|
-quiet, -q
|
be extra quiet
|
-verbose, -v
|
be extra verbose
|
-debug
|
print debugging information
|
-emacs
|
produce logging information without adornments
|
-logfile <file>
|
use given file for log
|
-1 <file>
|
‥
|
-logger <classname>
|
the class which is to perform logging
|
-listener <classname>
|
add an instance of class as a project listener
|
-buildfile <file>
|
use given buildfile
|
-file <file>
|
‥
|
-f <file>
|
‥
|
-D<property>=<value>
|
use value for given property
|
-propertyfile <name>
|
load all properties from file with -D
properties taking precedence
|
-inputhandler <class>
|
the class which will handle input requests
|
-find <file>
|
search for buildfile towards the root of the
filesystem and use it
|
3. 點擊Debug按鈕,程序將會在斷點處停留,這跟java application的調試一樣啦。