On 01/10/10 16:31, Per Eriksson wrote:
Hi,

Some additional info: the API is in the classpath of the component, but does not seem to be in the classpath of the org.xml.sax.helpers.XMLReaderFactory. This seems to be sax specific.

Noticed the following in the component:

SAXParser asd = new org.apache.xerces.parsers.SAXParser();  // Works

XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); // NoClassDefFoundError

The problem is probably that XMLReaderFactory.createXMLReader uses the Java context class loader to instantiate the argument SAXParser class, and the context class loader can be null, or any other class loader that does not happen to have access to the extension's xercesImpl.jar. You need something like (writing it down from memory):

ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(
  <your class>.class.getClassLoader());
try {
  parser = XMLReaderFactory.createXMLReader(...);
} finally {
  Thread.currentThread().setContextClassLoader(old);
}

Has been discuss extensively in the past, you can probably search the d...@ooo and [email protected] mailing list archives for it.

-Stephan

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to