解决ANT与JUNIT出现的问题

Ant 中使用 JUnit

  我提到过,如果要进行重构,必须有单元测试,这样才能确保不会破坏代码。 Eclipse 很好地支持 JUnit 。但我更愿意用 Ant 来构建和测试代码,在 Ant 中使用 JUnit 测试。如果您加载一个 Ant 构建文件到 Eclipse 中,运行 Junit Ant 任务,应该会看到:

BUILD FAILED: 
   D:/home/kevinj/Java/Security/
   tests.xml:94: Could not create 
   task or type of type: junit.

  该信息表明 Ant 没有找到任务或任务所依靠的类。 Ant 试图加载 Junit JAR 文件。当在 IDE 外部使用 Ant 时,应该把 junit.jar 放在 %ANT_HOME%/lib 文件夹。使用 Eclipse 时该任务无法工作,因为它使用自身版本的 Ant 。所以 junit.jar 必须放在 Eclipse 的 Ant 文件夹中,即 %ECLIPSE_HOME%/plugins/org.apache.ant_1.6.2/lib (很显然,不同版本的 Eclipse 会有不同版本的 Ant )。

除了以上步骤,还要配置Eclipse,进入Eclipse然后点击 Window->Preferences->ant->Runtime,然后选择'Ant Home Entries (Default).在点击按钮 'Add External JARs'.选择你junit.jar所在的位置,然后确定ok,再点击apply,你再重新运行该build.xml..........看..得左.是否很高兴?哈哈,我也有过的心情

<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> <rdf:Description rdf:about="http://docs.codehaus.org/display/GEOSDOC/Ant+-+junit%2C+build+failed%3D+Could+not+create+task+or+type+of+type+junit" dc:identifier="http://docs.codehaus.org/display/GEOSDOC/Ant+-+junit%2C+build+failed%3D+Could+not+create+task+or+type+of+type+junit" dc:title="Ant - junit, build failed= Could not create task or type of type junit" trackback:ping="http://docs.codehaus.org/rpc/trackback/37859" /> </rdf:RDF> --><!-- Root decorator: all decisions about how a page is to be decorated via the inline decoration begins here. --><!-- Switch based upon the context. However, for now, just delegate to a decorator identified directly by the context. -->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Readme - SwingLabs SwingX Project - http://swingx.dev.java.net<br><br><br>SwingX is a library of components and utilities extending the Java Swing library; read more at our website, <br>http://swingx.dev.java.net, and Wiki page, http://wiki.java.net/bin/view/Javadesktop/SwingLabsSwingX<br><br><br>Getting the Latest Source<br>=========================<br><br>1) Check out the lastest code<br>Download the latest release from our CVS repository; full instructions are at<br>https://swingx.dev.java.net/servlets/ProjectSource<br><br>but you can check out using the generic account "guest", with these settings<br><br>cvs -d :pserver:guest@cvs.dev.java.net:/cvs login<br><br>followed by<br><br>cvs -d :pserver:guest@cvs.dev.java.net:/cvs checkout swingx <br><br><br>Building the Source<br>===================<br>SwingX relies on Ant and Ant build files for controlling compilation, building docs, testing, etc. You can use our Ant build scripts or use your own--some IDEs make this easy to do.<br><br>To compile from the command line, you'll need to have Apache Ant installed; see http://ant.apache.org. <br><br>IMPORTANT: our default task in Ant also runs our unit tests, which are written using jUnit. You need to have Ant be aware of jUnit *before* compiling SwingX. We can't help you with <br>this--it's an Ant configuration issue. <br><br>If jUnit is not properly configured, you may get an error like this:<br> BUILD FAILED<br> c:\swingx\nbproject\build-impl.xml:407: Following error occured while executing this line<br> c:\\swingx\nbproject\build-impl.xml:127: Could not create task or type of type: junit.<br><br> Ant could not find the task or a class this task relies upon.<br><br>Suggestions: <br>- for Ant 1.5.x and previous, make sure optional.jar is in your ANT_HOME\lib directory.<br>- for Ant 1.6.x and above, make sure ant-junit.jar is in your ANT_HOME\lib directory, and that jUnit.jar is either in that directory as well OR listed on your CLASSPATH.<br><br>You can build SwingX by going to the command line and typing<br>ant<br><br>That should be it--this will test and build swingx.jar in the dist directory. <br><br><br>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值