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的调试一样啦。