纸飞机

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  22 随笔 :: 28 文章 :: 30 评论 :: 0 Trackbacks
今天在试着在eclipse中使用Ant来运行JUnit进行单元测试时弹出如下错误提示,但在外部窗口执行Ant时不会出现

BUILD FAILED
D:\EclipseWorkSpace\message\build.xml:
11: Could not create task or type of type: junit.

Ant could not find the task or a 
class this task relies upon.

This is common and has a number of causes; the usual 
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file: 
 - You have misspelt 'junit'.
   Fix: check your spelling.
 - The task needs an external JAR file to execute
     and this is not found at the right place in the classpath.
   Fix: check the documentation for dependencies.
   Fix: declare the task.
 - The task is an Ant optional task and the JAR file and/or libraries
     implementing the functionality were not found at the time you
     yourself built your installation of Ant from the Ant sources.
   Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the
     task and make sure it contains more than merely a META-INF/MANIFEST.MF.
     If all it contains is the manifest, then rebuild Ant with the needed
     libraries present in ${ant.home}/lib/optional/ , or alternatively,
     download a pre-built release version from apache.org
 - The build file was written for a later version of Ant
   Fix: upgrade to at least the latest release version of Ant
 - The task is not an Ant core or optional task 
     and needs to be declared using <taskdef>.
 - You are attempting to use a task defined using 
    <presetdef> or <macrodef> but have spelt wrong or not 
   defined it at the point of use

Remember that for JAR files to be visible to Ant tasks implemented
in ANT_HOME/lib, the files must be in the same directory or on the
classpath

Please neither file bug reports on this problem, nor email the
Ant mailing lists, until all of these causes have been explored,
as this
 is not an Ant bug.

按着错误提示将JUnit.jar放在ANT_HOME/lib中还是同样出现上述错误提示
这是因为<junit>任务在ant中是一个optinal task,非core task,需要junit.jar支持

解决方法:在window --> preferences --> Ant --> Runtime --> Classpath中选择Global Entries,然后添加JUnit.jar文件即可,以便eclipse在运行ant任务时会加载junit.jar,这样就可以解决上述问题现象,其实这里也可以将JUnit.jar文件放在Ant Home Entries,但这样有可能造成与Ant本身包的混淆.


ok

posted on 2007-07-19 22:41 纸飞机 阅读(2037) 评论(3)  编辑  收藏

评论

# re: Eclipse中使用Ant来运行Junit的错误及解决方法 2008-07-22 15:15 yhmymemory
刚才试了一下很好.  回复  更多评论
  

# re: Eclipse中使用Ant来运行Junit的错误及解决方法[未登录] 2008-12-05 11:03 user
谢谢  回复  更多评论
  

# re: Eclipse中使用Ant来运行Junit的错误及解决方法[未登录] 2009-07-24 11:25 ling
很不错。最近正为这个郁闷,现在解决了  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: