You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Domagoj Jugovic <do...@laus.hr> on 2002/06/14 16:03:36 UTC

junit task not working

<LOOP times="999999999999" message="PLEASE HELP !!!" />
I am running ant (1.4 and 1.5b2) on win98 , the build did'n work on 1.4 so 
I reached out for 1.5 and it's not working either.

I have a target called "junit" :
....................
<target name="junit" description="Performs all JUnit regression tests." >
<junit printsummary="yes" fork="yes" dir="${build.test}/ojb">
<classpath refid="runtime-classpath"/>
<formatter type="plain" />
<test name="test.ojb.broker.AllTests"
haltonfailure="no"
outfile="target/test/tests-broker" >
</test>
<test name="test.ojb.odmg.AllTests"
haltonfailure="no"
outfile="target/test/tests-odmg" >
</test>
<test name="test.ojb.soda.AllTests"
haltonfailure="no"
outfile="target/test/tests-soda" >
</test>
</junit>
</target>
...................

on that target I get printout like :
..................
junit:
BUILD FAILED
C:\java\ojb9\build.xml:407: 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 optional.jar is absent
Fix: look for optional.jar in ANT_HOME/lib, download if needed
- The task was not built into optional.jar as dependent
libraries were not found at build time.
Fix: look in the JAR to verify, then rebuild with the needed
libraries, or download a 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>.
............................

So I tried to fix things by manualy defining taskdef for "junit" task.
At the beginning of the build.xml I added :
<taskdef name="junit" 
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" 
classpathref="runtime-classpath"/>
Then I got this printout (Failing at my taskdef) :
..................
BUILD FAILED
C:\java\ojb9\build.xml:36: taskdef class 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask cannot be found
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java)
at 
org.apache.tools.ant.helper.ProjectHelperImpl$TaskHandler.finished(ProjectHelperImpl.java) 

at 
org.apache.tools.ant.helper.ProjectHelperImpl$AbstractHandler.endElement(ProjectHelperImpl.java) 

at 
org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:552) 

at 
org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:217) 

at 
org.apache.xerces.impl.XMLNamespaceBinder.emptyElement(XMLNamespaceBinder.java:594) 

at 
org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:817) 

at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:748) 

at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1454) 

at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:333) 

at 
org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserConfiguration.java:529) 

at 
org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserConfiguration.java:585) 

at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:147)
at 
org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1148)
at org.apache.tools.ant.helper.ProjectHelperImpl.parse(ProjectHelperImpl.java)
at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java)
at org.apache.tools.ant.Main.runBuild(Main.java)
at org.apache.tools.ant.Main.start(Main.java)
at org.apache.tools.ant.Main.main(Main.java)
--- Nested Exception ---
java.lang.NoClassDefFoundError: junit/framework/TestListener
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:496)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:117)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$300(URLClassLoader.java:69)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:544)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:203)
at java.lang.ClassLoader.loadClass(ClassLoader.java:325)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at java.lang.Class.getConstructors0(Native Method)
at java.lang.Class.getDeclaredConstructors(Class.java:1109)
at org.apache.tools.ant.AntClassLoader.initializeClass(AntClassLoader.java)
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java)
at 
org.apache.tools.ant.helper.ProjectHelperImpl$TaskHandler.finished(ProjectHelperImpl.java) 

at 
org.apache.tools.ant.helper.ProjectHelperImpl$AbstractHandler.endElement(ProjectHelperImpl.java) 

at 
org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:552) 

at 
org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:217) 

at 
org.apache.xerces.impl.XMLNamespaceBinder.emptyElement(XMLNamespaceBinder.java:594) 

at 
org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:817) 

at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:748) 

at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1454) 

at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:333) 

at 
org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserConfiguration.java:529) 

at 
org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserConfiguration.java:585) 

at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:147)
at 
org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1148)
at org.apache.tools.ant.helper.ProjectHelperImpl.parse(ProjectHelperImpl.java)
at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java)
at org.apache.tools.ant.Main.runBuild(Main.java)
at org.apache.tools.ant.Main.start(Main.java)
at org.apache.tools.ant.Main.main(Main.java)
..........................
So it can't find junit/framework/TestListener. OK
But this IS on the classpath ??? How this i possible ?
So I removed taskdef and added this :
(to see does VM sees that classes with the same classpath : "<classpath 
refid="runtime-classpath"/>" )
...................
<target name="junit" description="Performs all JUnit regression tests." >
<!-- ADDED STUFF ********to see will the VM find the 
classes***************************************** -->
<java classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" 
fork="no">
<classpath refid="runtime-classpath"/>
</java>
<java classname="junit.framework.TestListener" fork="no">
<classpath refid="runtime-classpath"/>
</java>
<echo message="---------------------------" />
<!-- END ADDED STUFF ************************************************* -->
<junit printsummary="yes" fork="yes" dir="${build.test}/ojb">
<classpath refid="runtime-classpath"/>
<formatter type="plain" />
<test name="test.ojb.broker.AllTests"
haltonfailure="no"
outfile="target/test/tests-broker" >
</test>
<test name="test.ojb.odmg.AllTests"
haltonfailure="no"
outfile="target/test/tests-odmg" >
</test>
<test name="test.ojb.soda.AllTests"
haltonfailure="no"
outfile="target/test/tests-soda" >
</test>
</junit>
</target>
...........................

Then I got the printout :
.............................
junit:
[java] Running in same VM Executing 
'org.apache.tools.ant.taskdefs.optional.junit.JUnitTask' with
fileset: Setup scanner in dir C:\java\ojb9\lib with patternSet{ includes: 
[**/*.jar, **/*.zip] excludes: [] }
force loading org.apache.tools.ant.taskdefs.optional.junit.JUnitTask
Finding class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask
Finding class org.apache.tools.ant.Task
Finding class org.apache.tools.ant.ProjectComponent
Class java.lang.Object loaded from parent loader
Class org.apache.tools.ant.ProjectComponent loaded from ant loader
Class org.apache.tools.ant.Task loaded from ant loader
Class java.lang.Throwable loaded from parent loader
Class java.lang.RuntimeException loaded from parent loader
Finding class org.apache.tools.ant.types.EnumeratedAttribute
Class org.apache.tools.ant.types.EnumeratedAttribute loaded from ant loader
Finding class 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask$SummaryAttribute
Class 
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask$SummaryAttribute 
loaded from ant loader
Finding class org.apache.tools.ant.taskdefs.optional.junit.BaseTest
Class org.apache.tools.ant.taskdefs.optional.junit.BaseTest loaded from ant 
loader
Finding class org.apache.tools.ant.taskdefs.optional.junit.JUnitTest
Class org.apache.tools.ant.taskdefs.optional.junit.JUnitTest loaded from 
ant loader
Finding class org.apache.tools.ant.BuildException
Class org.apache.tools.ant.BuildException loaded from ant loader
Class java.io.IOException loaded from parent loader
Class java.io.OutputStream loaded from parent loader
Class java.io.FileOutputStream loaded from parent loader
Finding class org.apache.tools.ant.taskdefs.ExecuteStreamHandler
Class org.apache.tools.ant.taskdefs.ExecuteStreamHandler loaded from ant 
loader
Class java.util.Hashtable loaded from parent loader
Class java.util.Properties loaded from parent loader
Class java.lang.ClassLoader loaded from parent loader
Finding class org.apache.tools.ant.AntClassLoader
Finding class org.apache.tools.ant.BuildListener
Class java.util.EventListener loaded from parent loader
Class org.apache.tools.ant.BuildListener loaded from ant loader
Class org.apache.tools.ant.AntClassLoader loaded from ant loader
Finding class 
org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
Finding class junit.framework.TestListener
Class junit.framework.TestListener loaded from ant loader
Class org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter 
loaded from ant loader
Finding class org.apache.tools.ant.taskdefs.LogOutputStream
Class org.apache.tools.ant.taskdefs.LogOutputStream loaded from ant loader
Class java.lang.Exception loaded from parent loader
[java] java.lang.NoSuchMethodException: main
[java] Running in same VM Executing 'junit.framework.TestListener' with
fileset: Setup scanner in dir C:\java\ojb9\lib with patternSet{ includes: 
[**/*.jar, **/*.zip] excludes: [] }
force loading junit.framework.TestListener
Finding class junit.framework.TestListener
Class java.lang.Object loaded from parent loader
Class java.lang.Throwable loaded from parent loader
[java] java.lang.NoSuchMethodException: main
[echo] ---------------------------
BUILD FAILED
C:\java\ojb9\build.xml:417: Could not create task or type of type: junit.
Ant could not find the task or a class this task relies upon.
.............................

So the VM can find these classes , but the "junit" task still does'n work 
(without or with my try to make new taskdef for it).
SO PLEASE HELP, I AM GOING MAD !



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: junit task not working

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: "Domagoj Jugovic" <do...@laus.hr>
To: <an...@jakarta.apache.org>
Sent: Friday, June 14, 2002 07:03
Subject: junit task not working


> <LOOP times="999999999999" message="PLEASE HELP !!!" />
> I am running ant (1.4 and 1.5b2) on win98 , the build did'n work on 1.4 so
> I reached out for 1.5 and it's not working either.
>
> I have a target called "junit" :
> ....................

>
> on that target I get printout like :
> ..................
> junit:
> BUILD FAILED
> C:\java\ojb9\build.xml:407: 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 optional.jar is absent
> Fix: look for optional.jar in ANT_HOME/lib, download if needed
> - The task was not built into optional.jar as dependent
> libraries were not found at build time.
> Fix: look in the JAR to verify, then rebuild with the needed
> libraries, or download a 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>.

We put that message in to reduce confusion; seems ok to me

> So I tried to fix things by manualy defining taskdef for "junit" task.
> At the beginning of the build.xml I added :
> <taskdef name="junit"
> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
> classpathref="runtime-classpath"/>
> Then I got this printout (Failing at my taskdef) :
> ..................
> BUILD FAILED
> C:\java\ojb9\build.xml:36: taskdef class
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTask cannot be found


That wont work because of this:
 - The task is not an Ant core or optional task
 and needs to be declared using <taskdef>.

you cannot redeclare stuff that is already declared; classpath issues:.


> ..........................
> So it can't find junit/framework/TestListener. OK
> But this IS on the classpath ??? How this i possible ?
> So I removed taskdef and added this :
> (to see does VM sees that classes with the same classpath : "<classpath
> refid="runtime-classpath"/>" )
> ...................
> <target name="junit" description="Performs all JUnit regression tests." >
> <!-- ADDED STUFF ********to see will the VM find the
> classes***************************************** -->
> <java classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
> fork="no">
> <classpath refid="runtime-classpath"/>
> </java>
> <java classname="junit.framework.TestListener" fork="no">
> <classpath refid="runtime-classpath"/>
> </java>

This was a brave effort, but it aint going to work.

>
> So the VM can find these classes , but the "junit" task still does'n work
> (without or with my try to make new taskdef for it).
> SO PLEASE HELP, I AM GOING MAD !


What was wrong with following this advice :

> - 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.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: junit task not working

Posted by Marko van Dooren <Ma...@cs.kuleuven.ac.be>.
I posted this message a while ago, maybe it can help you. It adds the 
junit.jar to the classpath and forks the VM. You need the change the path to 
junit.jar of course, the org.jutil.jar  must be replaced by the jar/classpath 
that you are testing.

--------------------------------------------------------------------------------------
I managed to get the junit task to work without removing it from optional.jar 
and without putting it in the $ANT_HOME/lib directory. My solution might not 
be the most elegant and efficient one, but it works without much trouble.

These 3 targets do the job

<!-- Set ANT_OPTS to "" if is doesn't exist yet
      otherwise "${ANT_OPTS}" will be given to the
      java VM -->
<target name="antopts" unless="ANT_OPTS">
  <property name="ANT_OPTS" value=""/>
</target>

<!-- Set classpath correct, fork VM and call second test stage -->
<target name="test" depends="compile,antopts">
  <!-- Add junit.jar and org.jutil.jar to the classpath -->
  <property name="testpath"v 
alue="${java.class.path}:${lib}/junit.jar:${lib.dist}/org.jutil.jar"/>
  <!-- Run ant again with a different target, but fork the VM so we can add 
  jars to the classpath                                  
   See Ant documentation for reasons why it doesn't work when using <junit> 
  directly. -->
  <java classname="org.apache.tools.ant.Main" fork="true" 
    classpath="${testpath}">
    <jvmarg line="-Dant.home=${ant.home} ${ANT_OPTS}"/>
    <arg line="test-secondstage"/>
  </java>
 </target>

<target name="test-secondstage" depends="init">
  <!-- perform tests here -->
</target>


I'm not sure whether it is cross-platform or not, I only use linux.

Happy junit testing,
------------------------------------------------------------------------------------------------


Marko No. 5
-- 
Jutil.org - Programming as you know it is over
http://org-jutil.sourceforge.net

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: junit task not working

Posted by Diane Holt <ho...@yahoo.com>.
Make sure you have both the optional tasks jar file and junit.jar -- then
read the second Note in the "Description" section on the Junit task page
(in the Ant1.5 manual):
  http://jakarta.apache.org/ant/manual/OptionalTasks/junit.html

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>