Classloading problem with using javax.script [message #504864] |
Wed, 23 December 2009 08:21 |
nick tan Messages: 56 Registered: July 2009 |
Member |
|
|
Hi, all
Recently, I encounter with a classloading problem with using javax.script.
here I have three bundles:
1. javax.script -- javax.script RI
2. com.x.y.groovy -- groovy and its dependencies
3. com.x.y.jelly -- jelly and its dependencies
4. com.x.y.test -- in which bundle, invokes the javax.script APIs (and it depends on bundle javax.script only)
As we all know that, javax.script is an adapter for different script engines, and it uses META-INF/services provider to load script engines.
And in eclipse, I defined the javax.script bundle's "Eclipse-BuddyPolicy" as "registered", to make sure the groovy and jelly ScriptEngineFactory can be loaded.
Since now, all the above works fine on JDK1.5 (you know that, javax.script RI is compatible with JDK1.5, even it is included by default since JDK1.6), I mean that the groovy script engine and the jelly script engine are all loaded and work to eval scripts.
But....
It does not work on JDK1.6.
1. code in com.x.y.test can't load the groovy/jelly script engines through buddy policy.
I think it's because the ContextFinder load the javax.script from system/bootstrap classloader (since javax.script is included in JDK1.6 by default), which not aware of the eclipse buddy policy.
Fine, the workaround is hard-coding, yes, I mean that make com.x.y.test depend on com.x.y.groovy and com.x.y.jelly, and register these script engines programmatically in codes of com.x.y.test
But, yes, unfortunately, another "BUT"...
It still does not work. And I get a ClassCastException:
Caused by: java.lang.ClassCastException: com.sun.script.jelly.JellyScriptEngineFactory cannot be cast to javax.script.ScriptEngineFactory
what I thought is, the two class (com.sun.script.jelly.JellyScriptEngineFactory and javax.script.ScriptEngineFactory) are loaded by different classloader which cause the ClassCastException
it's really strange
did I missing anything or did I overthought?
and idea is appreciated
Thank you all very much
|
|
|
Re: Classloading problem with using javax.script [message #505061 is a reply to message #504864] |
Sat, 26 December 2009 01:02 |
nick tan Messages: 56 Registered: July 2009 |
Member |
|
|
to summary, this problem occurred if and only if these conditions are true:
1. the library java meta-inf service provider is used (javax.script use service provider to load plugged script engine from classpath)
2. the library is included in JDK by default (here's javax.script RI, I think the same problem well be occurred with StAX RI)
3. this library is provided as a bundle in eclipse (OSGi)
is that right? I'm still NOT sure why the ClassCastException
my current workaround is really crazy, I copy the javax.script RI, and refactor the package name and it's service provider mechanism, and it sure works fine both on JDK 1.5 and JDK 1.6.
but is there any other solutions?
thank you very much!
[Updated on: Fri, 25 December 2009 20:09] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02600 seconds