Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
IdeaCapture.PNG
Ant Build in IntelliJ
[Thumbnail for IdeaCapture.PNG]
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic