NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Newer/Different version of Xerces?

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users
View previous topic :: View next topic  
Author Message
Cush1978



Joined: 15 Sep 2008
Posts: 334

PostPosted: Tue Nov 27, 2012 8:05 pm    Post subject: Newer/Different version of Xerces? Reply with quote

Hello,

I have a platform application and I'm trying to integrate a third party tool into it. The third party tool relies on a beta version of Xerces that provides XML Schema 1.1 support. NetBeans 7.2 ships with Xerces 2.8.0 as part of its core libraries.

My question is, how can I use the newer version of Xerces (2.11.0) with this third party tool without causing class loading issues?

Thanks!
Back to top
Jaroslav Tulach
Posted via mailing list.





PostPosted: Tue Nov 27, 2012 9:46 pm    Post subject: [platform-dev] Re: Newer/Different version of Xerces? Reply with quote

Dne
Back to top
Cush1978



Joined: 15 Sep 2008
Posts: 334

PostPosted: Wed Nov 28, 2012 2:18 am    Post subject: Reply with quote

??? All I see is "Dne" in your response.
Back to top
markiewb



Joined: 29 Aug 2012
Posts: 494

PostPosted: Wed Nov 28, 2012 5:45 am    Post subject: [platform-dev] Re: Newer/Different version of Xerces? Reply with quote

I think your email client has a problem. The message content is there. I repost the answer from jtulach for you.
Quote:
"I think the classloading problems are caused by
javax.xml.parsers.DocumentBuilderFactory.newInstance() trying to find all
implementations via META-INF/services/javax.xml.parsers.DocumentBuilderFactory
file. The system is using classloader which sees "everything" and then it does
not know whether to load the implementation class from 2.8.0 or 2.11.0. Does
that match your experience?
What can be done with that?
You can remove the META-INF/services/javax.xml.parsers.DocumentBuilderFactory
file from your 2.11.0 and access its classes directly.
You can package 2.11.0 so it is seen as a newer version of 2.8.0 module. Then
only the newer version should be enabled.
You can create a sample application, attach it to a bug/enhancement and hope I
will find some classloading trick to load the right implementation."
Greetings markiewb Am 28.11.2012 03:18 schrieb "Cush1978" <address-removed ([email]address-removed[/email])>:
Quote:
???
Back to top
Cush1978



Joined: 15 Sep 2008
Posts: 334

PostPosted: Wed Nov 28, 2012 1:04 pm    Post subject: Reply with quote

Hi, thanks for posting the response. I'm actually posting via the NetBeans Forum and I've seen responses get truncated before. Sometimes the forum gets the formatting wrong and loses the content of an email reply.

I'll try some of the solutions and see what works. The third party tool specifically uses some classes from the 2.11.0 implementation, so if I remove the service registration, that should work. I'll post back with results.
Back to top
Cush1978



Joined: 15 Sep 2008
Posts: 334

PostPosted: Wed Nov 28, 2012 10:10 pm    Post subject: Reply with quote

OK, so I tried removing the services from the 2.11.0 implementation. Then it complained that it couldn't find any parser to handle XML Schema 1.1. Looking closely at the services folder, I found a service:

Code:
javax.xml.validation.SchemaFactory


which declares
Code:

org.apache.xerces.jaxp.validation.XMLSchemaFactory
org.apache.xerces.jaxp.validation.XMLSchema11Factory


The entire point of using the newer Xerces is to have XML Schema 1.1 compliance, so I left that service declaration in. Now I'm getting a class loading collision trying to load
Code:
org.apache.xerces.dom.DOMXSImplementationSourceImpl
arbitrarily from the original Xerces module and my newer one. Even though I removed that service from the new JAR, it seems to still attempt to load the class.

Quote:
You can package 2.11.0 so it is seen as a newer version of 2.8.0 module. Then only the newer version should be enabled.


How would I do this? I'm not entirely sure Xerces IS a module, it seems like a core JAR packaged with NetBeans, but I could be wrong there.
Back to top
Cush1978



Joined: 15 Sep 2008
Posts: 334

PostPosted: Fri Nov 30, 2012 5:02 pm    Post subject: Reply with quote

Well I've found a solution that seems to work. Here's how I did it in case anyone needs to do it in the future.

- Wrap the new Xerces JAR in the same module as the library that needs it.

This is usually inadvisable, but in this case that specific module is the only one that needs specific functionality from that specific version of Xerces.

- Remove the META-INF/services directory from the new Xerces JAR.

We don't want to offer any services, we're directly invoking the classes we want to use as opposed to a factory method.

- Replace the context class loader when calling Xerces code.

http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html#overlaps

See the specific note on Xerces.

Code:
ClassLoader original = Thread.currentThread().getContextClassLoader();

// Use the module's ClassLoader.
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

// Do Xerces stuff here.

// If there's exception handling, use a finally block.
Thread.currentThread().setContextClassLoader(original);


At this point, the code works. I do get a logged warning about arbitrarily loading classes from two sources, but there is no thrown exception. Note that this case is a specific end case and doesn't "upgrade" or "replace" Xerces functionality. It just allows me to use a newer Xerces JAR and call the specific classes needed within.
Back to top
Jaroslav Tulach
Posted via mailing list.





PostPosted: Sun Dec 02, 2012 2:17 pm    Post subject: [platform-dev] Re: Newer/Different version of Xerces? Reply with quote

Good to hear there is an solution. It is not very nice, you are right, but
better some solution than none.
-jt

Dne P
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo