Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found." while running "ant test"?

Tags:

I have a target named test and I want to do some tests.

I put here the important parts in build.xml. It includes:

<property name='lib.dir' value='lib' />  <path id='classpath'>      <fileset dir="${lib.dir}" includes="**/*.jar" /> </path> 

And I have put the junit.jar and ant-junit.jar(is it a must?) in the lib directory.

However, if I run

ant test.

The output error is:

test:  BUILD FAILED /home/xiaohan/EclipseWorkSpace/AntTest/build.xml:82: Problem: failed to create task or type junit Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.         This looks like one of Ant's optional components. Action: Check that the appropriate optional JAR exists in         -/usr/share/ant/lib         -/home/xiaohan/.ant/lib         -a directory added on the command line with the -lib argument  Do not panic, this is a common problem. The commonest cause is a missing JAR.  This is not a bug; it is a configuration problem 

Additionally, if I put the two jar files in /usr/share/ant/lib with the $ANT_HOME set, it still does not work.

Really thanks for any hints

like image 247
xiaohan2012 Avatar asked Jul 04 '11 07:07

xiaohan2012


2 Answers

In my case (using Mint, based on Debian)

sudo apt-get install ant-optional 

was the only thing that worked.

like image 102
Lucia Pasarin Avatar answered Nov 13 '22 02:11

Lucia Pasarin


The issue was solved on RHEL-based systems once ant-junit was installed:

$ sudo yum install ant-junit 
like image 22
null Avatar answered Nov 13 '22 01:11

null