wood burning stoves 2.0*
The moose likes IDEs, Version Control and other tools and the fly likes IntelliJ Ant task fail:  Junit Could Not Be Found in Your Classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "IntelliJ Ant task fail:  Junit Could Not Be Found in Your Classpath" Watch "IntelliJ Ant task fail:  Junit Could Not Be Found in Your Classpath" New topic
Author

IntelliJ Ant task fail: Junit Could Not Be Found in Your Classpath

Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

building a project using ant with IntelliJ Idea.
I'm getting the following errors when running my test tasks in ant:
C:\Users\mcguit1\Downloads\DriverSource\build.xml:378: JUnit could not be found in your classpath. You must download and install it from http://junit.org to build and run the test suite.

here is the ant target that fails:


Note: These steps work fine when I run ant testjar from command line, but inside intelliJ, I experience errors. I've attached a screenshot proving that junit.jar is right there in my External Libraries. I used the one that comes with IntelliJ IDEA.
I also tried adding the path to junit.jar inside the classpath element of the above ant task, but it did not work. What Am I Missing?

Thanks!



[Thumbnail for IdeaCapture.PNG]

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9924
    
158

I don't think this has anything to do with classpath. Looking at that build file, there's an explicit "fail" unless the "junit" property is set somewhere in that build project.
Tim McGuire wrote:building a project using ant with IntelliJ Idea.
I'm getting the following errors when running my test tasks in ant:
C:\Users\mcguit1\Downloads\DriverSource\build.xml:378: JUnit could not be found in your classpath. You must download and install it from http://junit.org to build and run the test suite.

here is the ant target that fails:
[code=xml]
<!-- This compiles and builds the test jarfile. -->
<target name="testjar" depends="jar">
<fail message="JUnit could not be found in your classpath. You must download and install it from http://junit.org to build and run the test suite." unless="junit" />


Apparently, when being run via IDE, that property isn't getting set. So you'll have to figure out which part of that build script sets that property and why it isn't being set while being run in IDE.

[My Blog] [JavaRanch Journal]
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Thanks! that makes perfect sense and helped me solve the problem:

The property is set here:



It did have something to do with classpath as IntelliJ's ANT gets its junit via its own classpath (it uses ant-junit.jar from C:\Program Files (x86)\JetBrains\IntelliJ IDEA 10.5.4\lib\ant\lib
and that jar has no such thing as framework.Test )

my command line ant had access via my system classpath to junit.jar which does have a junit.framework.Test

So, once I put junit.jar into ANT's classpath (a different thing than intelliJ's classpath or project libraries) it started working

Now that I learned the reason, I see that the ant documentation says clearly that junit.jar must be in classpath in addition to ant-junit.jar:
http://ant.apache.org/manual/Tasks/junit.html


Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

and now I see that the ANT integration in IntelliJ IDEA has a nice feature called the additional classpaths tab (http://www.jetbrains.com/idea/webhelp/defining-additional-ant-classpath.html) where I can add extra jars to my ant classpath.
 
jQuery in Action, 2nd edition
 
subject: IntelliJ Ant task fail: Junit Could Not Be Found in Your Classpath
 
Similar Threads
JUnit not found...
Howto run specific JUnit tests in ant?
Problem with ANT compiling but not doing jar
Ant+JUnit
Problem with ANT compiling but not doing jar