• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
[Thumbnail for IdeaCapture.PNG]
Ant Build in IntelliJ
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic