2

I need the class DocumentImpl, which is available in xercesImpl.jar via path org/apache/xerces/dom/DocumentImpl. But my code fails because of missing com/sun/org/apache/xerces/internal/dom/DocumentImpl. If I add jaxp-ri.jar to the classpath it works, but I don't want to use jaxp-ri.jar, if I already have the class.

From the classloading policy, my xercesImpl.jar is loaded first. Is there a way to tell my code to use the path org/apache/xerces/dom/ instead of com/sun/org/apache/xerces/internal/dom/? Via JVM args?

Why is the second path used anyway?

I am running my servlet on a websphere application server. Thank you

Edit: Here is my trace:

Caused by: java.lang.NoClassDefFoundError: com.sun.org.apache.xerces.internal.dom.DocumentImpl
    at java.lang.ClassLoader.defineClassImpl(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:275)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:74)
    at com.ibm.ws.classloader.CompoundClassLoader._defineClass(CompoundClassLoader.java:833)
    at com.ibm.ws.classloader.CompoundClassLoader.localFindClass(CompoundClassLoader.java:746)
    at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:587)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:665)
    at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.<init>(SOAPPartImpl.java:96)
    at com.sun.xml.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl.<init>(SOAPPart1_1Impl.java:68)
    at com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl.getSOAPPart(Message1_1Impl.java:88)
    at myclass.CreateMessage(myclass.java:1337)

Edit2: I use non Oracle-JVM. I also added these JVM Parameters:

-Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser
-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
-Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl
-Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.MessageFactoryImpl
user30137
  • 63
  • 1
  • 9
  • Who calls DocumentImpl, which lib are you using? without knowing these detaisl we cant help.. am afraid.. – SMA Apr 28 '15 at 08:14
  • I suspect you are having trouble with a non-Oracle JVM (IBM J9?). Try setting the DocumentBuilderFactory (see Q14 https://jaxp.java.net/1.4/JAXP-FAQ.html) – artbristol Apr 28 '15 at 08:28
  • Yes, non Oracle-JVM. I tried to set it via: -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl but this was not sufficient. – user30137 Apr 28 '15 at 08:29
  • Which WebSphere version and JDK version are you using? Did you try to remove `xercesImpl.jar` from your application? – Gas Apr 28 '15 at 10:51
  • JDK 1.6, WAS8. I want to use xercesImpl.jar. – user30137 Apr 28 '15 at 11:13
  • WAS 8.0 already provides Xerces libraries in the runtime (xml.jar) and other xml related libs. And it provides it in the org/apache/xerces/dom/DocumentImpl package. Any reason why you want to use external one? You are probably also attaching some other xml related libraries in you app, which refers to the com.sun packages. – Gas Apr 28 '15 at 11:59

1 Answers1

0

I would try referencing the class via its complete path explicitly in the code.

It could be as trivial as your IDE resolving the undesired import automatically.

org.apache.xerces.dom.DocumentImpl myVariable;
Mena
  • 47,782
  • 11
  • 87
  • 106