Skip to main content

A class needed by class com.sun.tools.jxc.SchemaGenTask cannot be found

3 replies [Last post]
tigera
Offline
Joined: 2007-07-15

Last night, I upgraded my OS and Netbeans stopped working. I reinstalled Netbeans, and now when I try to run my schemagen ant task, I get this:

/home/markelba/Projects/momme_java/MOMMEModelSources/test/net/momme/Battle/generateSchema.xml:4: taskdef A class needed by class com.sun.tools.jxc.SchemaGenTask cannot be found: org/apache/tools/ant/taskdefs/Javac

I have put the JAXB 2.1.5 implementation into my $JAVA_HOME/jre/lib directory (jaxb-api.jar) and I even tried removing the jaxws implementation that came with Netbeans. I've also tried upgrading from 5.5.1 to 6.0 b2 and it still doesn't work.
The JDK implementation is jdk-6u2. What can I do to fix this?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
michaelepley
Offline
Joined: 2007-10-25

I'm cannot speak to any any Netbeans issues, but this appears to be an Ant issue (which netbeans uses for builds). Having just fixed an almost identical problem with my eclipse install, I can hopefully help.

The solution is simple: 1) you must place exactly one file in the $JAVA_HOME/jre/lib/endorsed directory, jaxb-api.jar. 2) remove JAXB from your $JAVA_HOME/jre/lib/ext directory if present , and 3) ensure the remainder of JAXB and Ant is accessible via your classpath (possible done automagically by netbeans).

The class com.sun.tools.jxc.SchemaGenTask is being loaded by a classloader (probably the bootstrap or extensions loader) which is a parent to than the classloader loading org/apache/tools/ant/taskdefs/Javac (probably from a custom ant classloader). Thus the loader for SchemaGenTask cannot find an implementation of Javac. The steps above will ensure both JAXB (read: XJCTask) and Ant are loaded by the same system classloader and can thus find each other. See http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html for more info.

tigera
Offline
Joined: 2007-07-15

Thanks, you managed to put the train back on the tracks with that one :-)
I'll have to remember that - ONE file, and ONE file only. When I took everything out of the endorsed directory, it began to work.
I wonder why it broke when I updated Ubuntu.

tigera
Offline
Joined: 2007-07-15

P.S. - When I copy the ant jars out of the Netbeans directory, I now get this:
java.lang.ClassCastException: org.apache.tools.ant.helper.DefaultExecutor cannot be cast to org.apache.tools.ant.Executor
at org.apache.tools.ant.Project.getExecutor(Project.java:1166)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:277)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:460)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)
BUILD FAILED (total time: 0 seconds)