ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Taemin Cim" <>
Subject Broken Junit targets
Date Tue, 14 Feb 2006 01:54:35 GMT
Hi All!

I've broken my junit task in Ant...I got an error in a side project where it 
couldnt import TestCase, so I copied the junit.jar into the lib dir for that 
project, and got "could not create task of type junit" when I ran Ant.
So I realized Ant has its own ant-junit.jar, so I deleted the junit.jar 
which I had moved, but now ALL my projects are broken for running tests from 
Ant, even though I put things back to the way they were before.  I rebooted, 
etc.  Why would this side project effect all junit tasks?

In my build file I have the junit jar included only for tests.
  <path id="compile.classpath">
    <pathelement path ="lib/hibernate3.jar"/>
    <pathelement path ="lib/commons-lang-1.0.1.jar"/>
    <pathelement path ="lib/commons-logging-1.0.4.jar"/>

  <path id="test.classpath"><path refid="compile.classpath"/><pathelement 
    <pathelement location="${build.dir}/classes"/>
    <pathelement location="${build.dir}/test"/>

The complie works, but the tests fail:

build.xml:154: 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 
or fix the build file:
- You have misspelt 'junit'.  				<--- NOT THE PROBLEM
	Fix: check your spelling.
- The task needs an external JAR file to execute
	and this is not found in the right place in the classpath <--- NOT THE 
	Fix: check the documentation for dependencies.			Ant's Junit class worked 
fine before
	Fix: declare the task.
- The task is an Ant optional task and the JAR file and/or libraries <--- 
	implementing the functionality were not found at the time you	   I didn't 
build ant myself
	yourself built your installation for Ant from the Ant sources.
	Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the   
<--- ant-junit.jar is there
	task and make sure it contains more than merely a META-INF/MANIFEST.MF.
	If all it contains is the manifest, then rebuild Ant with the needed     
<--- checked the jar, it&#347; good
	libraries present in ${ant.homw}/lib/optional/ , or alternatively,
	download a pre-built release version from
- The build file was written for a later version of Ant				 <--- my build 
file didn't change
	Fix: upgrade to at least the latest release version of Ant		      from when 
junit tagets ran
- The task is not an Ant core or optional task and needs to be declared 
using <taskdef>  <--- NOT THE PROBLEM
- You are attempting to use a task defined using		<--- NOT THE PROBLEM
	<presetdef> or <macrodef> but have spelt wrong or not
	defined it at the point of use
Remember that for JAR files to be visible to Ant tasks implemented in
	ANT_HOME/lib, the files must be in the same directory or on the classpath.
Please netither file bug reports on this problem, nor email the
	Ant mailing lists, until all of these causes have been explored,
	as this is not an Ant bug.

Here is the test target:

  <target name="test-batch" depends="test-compile">
    <junit printsummary="withOutAndErr" haltonfailure="false">   <-- line 
      <classpath refid="test.classpath"/>
      <formatter type="brief" usefile="true"/>
      <formatter type="xml"/>
      <batchtest todir="${}">
        <fileset dir="${test.dir}" includes="**/*Test.class"/>
    <junitreport todir="${}">
      <fileset dir="${}">
        <include name="TEST-*.xml"/>
      <report format="frames" todir="${test.reports.dir}"/>

in properties.xml

  <property name="junit.dir"   location="${ant.home}/lib"/>

    <property name="junit.subdir"      value=""/>

    <property name="junit.jar" 

    I changed junit.jar to ant-junit.jar:

    <property name="junit.jar" location="${junit.dir}/ant-junit.jar"/>

Still got the error.
I have two junit.jar files:

in junit3.8.1 which is used for the JUNIT_HOME variable


in apache-ant-1.6.5/lib/ant-junit.jar

could there be a conflict between the junit.jar in the JUNIT_HOME variable 
and the ant/lib/ant-junit.jar when running the junit task from ant?

/home/timmy/apache-ant-1.6.5/lib/ant-junit.jar and 

I found this post on the mailing lists after googling:

> > But I have notified that I have two junit.jars in the above
> > classpath. One in the ANT/lib dir (so that Ant knows of the junit
> > task) and one in the project classpath (WEB-INF/lib) . Could that
> > cause any problems ?
>No, at least not as long as both are the same version.

In the ant-junit.jar manifest I found:

Ant-Version: Apache Ant 1.6.5
MY version : apache-ant-1.6.5

So, as the poster said, shouldn't be a problem.  Keep in mind, before this 
fiasco, I had the tests running from this side project fine.  I still don't 
know why all of a sudden the build couldn't find TestCase and made me copy 
the junit.jar to the subprojects lib in the first place, consequently 
messing up all my projects testing ability!
Keep in mind, I've been using junit tasks on this particular box running 
Fedora Core 3 for over a year, with no changes to the jars.  The sub project 
is a Hibernate learning project.  I can't get Hibernate configured correctly 
to talk to MySQL, so I made a sub project to test the connection.  This 
seems like too much info, so I'm sorry for overdoing it.

Thanks for your time


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message