A class needed by class <...> cannot be found: org/apache/tools/ant/Task

(I spent quite a few hours fighting this one, so hopefully Google will help others find this page…) After toying around with maven a bit, I discovered that none of my ant tasks would run. I hadn’t made any changes to anything in $ANT_HOME, but all of sudden things broke. What I had done without thinking about it was to place woproject.jar in /Library/Java/Extensions. This jar contains the classes to create a few Ant task definitions. So here’s the rule…

Never place jars that are necessary for Ant task definitions in your Java classpath (/System/Library/Java/Extensions, /Library/Java/Extensions/, ~/Library/Java/Extensions)

The problem is that Java tries to load these jars before it has loaded the Ant jars that they rely on. These jars that contain task definitions should either be placed in the Ant classpath ($ANT_HOME/lib, ~/.ant/lib) or in your project’s lib directory and referenced directly using the classpath attribute of the taskdef.

Comments and responses

THanks a lot, you saved me big time. In my case I had JAXWS .jar files in my JAVA_HOME/lib/endorsed folder and that threw things off.
Excellent!! Sharing ur experience..saved me time,energy..and more over fresh insight into my problem.. .. thank u very much

I got this issue when I tried to set up a web service app with jaxws 2.1 to work.

I was having another issue, followed a link online suggested that all the jars for jaxws 2.1 should be put in jre/lib/endorsed. One of the jar file which defines Apt ant task is jaxws-tools.jar.And this stopped my Ant task invoking from eclipse to work.

Followed your instruction, i removed the endorsed dir from jdk1.6 dir and things started working again.

>so hopefully Google will help others find this pageā€¦

Indeed, it did. You’re even on rank one for that search.

So: Thank you very much, saved me a huge WOMBAT!