Different behavior calling the same library from Java main() vs from a JFace part [message #1142711] |
Thu, 17 October 2013 20:17 |
Charles Li Messages: 16 Registered: December 2009 |
Junior Member |
|
|
I created an Eclipse 4 RCP project with GUI. In one ViewPart I need to call a utility Java library I created (Apache Jena), but I experienced ClassCastException:
Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:121)
at java.util.XMLUtils.getLoadingDoc(XMLUtils.java:92)
at java.util.XMLUtils.load(XMLUtils.java:74)
at java.util.Properties.loadFromXML(Properties.java:868)
at com.hp.hpl.jena.util.Metadata.read(Metadata.java:76)
at com.hp.hpl.jena.util.Metadata.addMetadata(Metadata.java:54)
at com.hp.hpl.jena.util.Metadata.<init>(Metadata.java:48)
at com.hp.hpl.jena.JenaRuntime.<clinit>(JenaRuntime.java:34)
... 81 more
If I create a pure main() Java program in the same Eclipse 4 RCP project and call the same utility Java program, it execute successfully.
In the viewPart, I didn't even import any Apache Jena packages. Apparently the class loading were different in the two cases.
So how should I approach to resolve this ClassCastException?
Thanks a lot!
[Updated on: Thu, 17 October 2013 20:26] Report message to a moderator
|
|
|
|
|
Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1144264 is a reply to message #1144023] |
Fri, 18 October 2013 19:16 |
Charles Li Messages: 16 Registered: December 2009 |
Junior Member |
|
|
Problem not resolved yet, but more findings:
Within the command-line execution and the RCP GUI execution, I used "System.getProperties()" to list all system properties, and I found the following system property was set in the former but not in the latter, although I didn't do anything in either cases.
javax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
So I am trying to add the above system property to the latter, and I tried the following (each one by itself only) but none was successful (the ClassCastException still showed up):
- Run Configuration > Arguments: add "-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl" to "Program arguments.
- Run Configuration > Arguments: add "-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl" to "VM arguments.
- .product configuration > Configuration tab: add "javax.xml.parsers.DocumentBuilderFactory" and "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl" as name/value under "Properties.
Please help! Thanks!
[Updated on: Fri, 18 October 2013 19:18] Report message to a moderator
|
|
|
|
|
Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1145299 is a reply to message #1144531] |
Sat, 19 October 2013 12:03 |
Eclipse User |
|
|
|
Charles Li wrote on Sat, 19 October 2013 01:38More findings: whenever I call the utility Java library from within a method with dependency injection, the ClassCastException occurs; while the same call from any regular Java class/method without DI, it is successful.
It seems the call to the Java library uses a third-party open-source library, where it parses an XML config file - don't know if this helps with finding out what is wrong.
So my question is - is there anything unique about the Java execution environment with DI? Does it carry the XML parser that comes with the JDK? I am using Java 1.7.
Thanks a lot!
In the eclipse 4 case you should have javax.xml in your running config so it may get in your way of doing things.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05808 seconds