PreviousNextTracker indexSee it online !

(37/211) 3206 - JARClassLoader's URLs are not understood by Ant's Locator

JARClassLoader's URLs are not understood by Ant's Locator.

This causes the javah ant task to fail if the ant target is invoked from
AntFarm using jEdit's JVM.

The problem arises as the javah task first obtains a class object with a call to Class.forName("com.sun.tools.javah.oldjavah.Main") and then asks Ant's Locator to find the path to this class' containing jar file (which the javah task uses as a means to locate tools.jar).

See:
org.apache.tools.ant.launch.Locator
org.apache.tools.ant.taskdefs.optional.javah.SunJavah


This becomes a problem when Ant is run from AntFarm in jEdits JVM as the class com.sun.tools.javah.oldjavah.Main is loaded using the JARClassLoader. Ant's Locator then calls the JARClassLoader's getResource(String name) and tries to determine the path to the jar file from the returned URL.

However JARClassLoader returns a URL like this
"jeditresource:/tools.jar\!/com/sun/tools/javah/oldjavah/Main.class"

But Locator does not understand the jeditresource: protocol (and even if it did the URL lacks the full path information to tools.jar anyway).

Subsequently the javah task then invokes java without tools.jar in the classpath resulting in
java.lang.NoClassDefFoundError: com/sun/tools/javah/oldjavah/Main

For a quick fix I tweaked my build of jEdit so that JARClassLoader
returns URLs in the form
“jar:file:/usr/lib/jvm/java-6-sun-1.6.0.10/lib/tools.jar\!/com/sun/tools/javah/oldjavah/Main.class”
These URLs are then understood by Locator and thus this fixes the javah task. I don't know if this is the best way to fix this, or what other problems this may introduce.

Submitted nigelt - 2008-12-13 13:36:38 Assigned
Priority 5 Labels editor core
Status open Group None
Resolution None

Comments