Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Classloading problem with using javax.script
Classloading problem with using javax.script [message #504864] Wed, 23 December 2009 08:21 Go to next message
nick tan is currently offline nick tanFriend
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 Go to previous messageGo to next message
nick tan is currently offline nick tanFriend
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

Re: Classloading problem with using javax.script [message #505915 is a reply to message #505061] Tue, 05 January 2010 14:43 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Can you not update the javax.script bundle to only load in 1.5? Then it
wouldn't interfere with your java 1.6 version.

But then that won't help you with your buddy policy, since the
javax.script included with 1.6 can't see OSGi.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:How to sum up packages?
Next Topic:Problem with IEvaluationContext.UNDEFINED_VARIABLE
Goto Forum:
  


Current Time: Fri Apr 26 13:49:40 GMT 2024

Powered by FUDForum. Page generated in 0.02600 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top