Hi, I think the root cause of the issue is something a little more fundamental with Karaf 4.2.0:
Java 9 removed the endorsed mechanism that could override classes from the JDK. Karaf versions before 4.2.0 used that mechanism to replace some javax APIs (like the Stax API javax.xml.stream) with a servicemix wrapped implementation which was changing the implementation lookup in a way that was working with OSGi. Without that endorsed stuff, you will fall back to the JDK implementation of XMLInputFactory which finds the services definition from Woodstox (which says that com.ctc.wstx.stax.WstxInputFactory is the XMLInputFactory implementation to use) and then tries to load that class with its own class loader (the root class loader) or the ThreadContextClassLoader. Now you have different options (which all have their disadvantages): 1. As you already found out you can import the Woodstox packages from all bundles using Stax and set the Thread Context Class loader to the class loader of that bundle. The disadvantage of that approach is that the bundle using Stax has to know about the implementation (which is not supposed to be the case). 2. Put woodstox into the system classloader (into ext or endorsed) and export the packages from the system bundle. The disadvantage of this approach is that this will only work with Java 8 (not with Java 9 and later). Alternatively you could put the servicemix wrapped Stax API into the endorsed folder (as with older Karaf versions), which will also only work with Java 8. 3. Import the woodstox bundle into the bundle using Stax and instantiate the factory implementations directly (not via the Interface). Here the using bundle needs to control the factory instantiaton, but you don’t need to set the thread context class loader. I have not yet figured out what the real solution about that is supposed to look like. I have asked that question already to the karaf-dev list (because the question is actually how Karaf 4.2 and later is supposed to handle the SPI pattern), but I didn’t get an answer for it. Best regards Stephan From: [email protected] [mailto:[email protected]] On Behalf Of [email protected] Sent: Mittwoch, 21. März 2018 18:35 To: [email protected] Subject: Re: Karaf 4.2.0M2 issue with classpath If you have control over that code then the TCCL is a good solution. Christian 2018-03-21 16:54 GMT+01:00 bobanbp <[email protected]<mailto:[email protected]>>: Hi Christian, Thanks for your reply. I tried your suggestion but without success. The only solution that works is to explicitly change class loader: ClassLoader tccl = Thread.currentThread() .getContextClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); my code that uses AWS SDK Thread.currentThread().setContextClassLoader(tccl); -- Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html -- -- Christian Schneider http://www.liquid-reality.de Computer Scientist http://www.adobe.com
