[groovy-user] Groovy and OSGi

5 views
Skip to first unread message

Robert Fischer

unread,
Aug 15, 2009, 3:38:31 PM8/15/09
to us...@groovy.codehaus.org
I've got a simple Groovy bundle that I'm executing via OSGi. When it fires up, though, I get an
error, which seems to indicate that it can't find org.w3c.dom.NodeList — but that's part of the Java
SDK!

If I add org.w3c.dom as a required import, I get an exception complaining about there not being a
satisfying match in another bundle.

Now, there's a sample at http://groovy.codehaus.org/OSGi+and+Groovy which shows a BundleActivator,
and it actually jacks the context classloader (basically promoting itself up a notch). Why does it
have to do this? Is this to address some underlying problem with Groovy? Does it do some kind of
ClassLoader manipulation stunt which breaks within OSGi?

Here's the exception, should you be curious:

[java] Exception in thread "main" org.osgi.framework.BundleException: Activator start error in
bundle groovy16 [3].
[java] at org.apache.felix.framework.Felix.startBundle(Felix.java:1506)
[java] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:779)
[java] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:760)
[java] at eg.OSGiRuntime.loadBundleFile(Unknown Source)
[java] at eg.Driver.main(Unknown Source)
[java] Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/NodeList
[java] at java.lang.Class.getDeclaredMethods0(Native Method)
[java] at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
[java] at java.lang.Class.getDeclaredMethods(Class.java:1763)
[java] at org.codehaus.groovy.reflection.CachedClass$3$1.run(CachedClass.java:83)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:80)
[java] at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:78)
[java] at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:33)
[java] at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:20)
[java] at org.codehaus.groovy.reflection.CachedClass.getMethods(CachedClass.java:252)
[java] at
org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:138)
[java] at
org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:87)
[java] at
org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:65)
[java] at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:28)
[java] at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:151)
[java] at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:170)
[java] at
eg.impl.groovy16.Groovy16HelloWorldBundle.$getStaticMetaClass(Groovy16HelloWorldBundle.groovy)
[java] at eg.impl.groovy16.Groovy16HelloWorldBundle.<init>(Groovy16HelloWorldBundle.groovy)
[java] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[java] at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[java] at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[java] at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
[java] at java.lang.Class.newInstance0(Class.java:350)
[java] at java.lang.Class.newInstance(Class.java:303)
[java] at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3350)
[java] at org.apache.felix.framework.Felix.startBundle(Felix.java:1453)


~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/gormbook

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Robert Fischer

unread,
Aug 15, 2009, 4:08:58 PM8/15/09
to us...@groovy.codehaus.org
More discoveries.

1) The classloader stunt outlined on the wiki doesn't seem to solve anything. The problem is when
my Groovy Activator class is being loaded, so the code that'd mangle the class path never even gets
a chance to execute.
2) The system bundle can load the NodeList class just fine.
3) Adding org.w3c.dom as an Import-Package gives an "Unresolved constraint" in org.w3c.dom

~~ Robert.

Robert Fischer

unread,
Aug 15, 2009, 4:09:15 PM8/15/09
to us...@groovy.codehaus.org
More discoveries.

1) The classloader stunt outlined on the wiki doesn't seem to solve anything. The problem is when
my Groovy Activator class is being loaded, so the code that'd mangle the class path never even gets
a chance to execute.
2) The system bundle can load the NodeList class just fine.
3) Adding org.w3c.dom as an Import-Package gives an "Unresolved constraint" in org.w3c.dom

~~ Robert.

Robert Fischer

unread,
Aug 15, 2009, 4:20:13 PM8/15/09
to us...@groovy.codehaus.org
Hamlet D'Arcy figured it out: you need to explicitly tell the system bundle what packages it
provides, and I didn't have org.w3c.dom in that list.

Hamlet D'Arcy

unread,
Aug 15, 2009, 4:51:02 PM8/15/09
to us...@groovy.codehaus.org
Just documenting the solution for future readers.

You must need to tell your container to expose that package as part of
the system bundle.

Something like this in config.ini:

org.osgi.framework.system.packages=org.w3c.dom,org.w3c.dom.traversal,
org.w3c.dom.ls, javax.sql, javax.transaction

Check out these directions:

http://docs.codehaus.org/display/JETTY/OSGi+Tips

--
Hamlet D'Arcy
haml...@gmail.com

Hamlet D'Arcy

unread,
Aug 15, 2009, 4:52:57 PM8/15/09
to us...@groovy.codehaus.org
> Hamlet D'Arcy figured it out: you need to explicitly tell the system bundle
> what packages it provides, and I didn't have org.w3c.dom in that list.

I think it's slightly different for each container. Equinox specifies
a config.ini that you put this in:

org.osgi.framework.system.packages=org.w3c.dom,org.w3c.dom.traversal,
org.w3c.dom.ls, javax.sql, javax.transaction

But I'm guessing that isn't part of the OSGi spec and just part of
Equinox. I don't know though.

--
Hamlet D'Arcy
haml...@gmail.com

---------------------------------------------------------------------

Robert Fischer

unread,
Aug 15, 2009, 4:56:42 PM8/15/09
to us...@groovy.codehaus.org
I'm doing embedded Felix, and the solution is to add org.w3c.dom onto the string value of the
Constants.FRAMEWORK_SYSTEMPACKAGES.

~~ Robert.

Reply all
Reply to author
Forward
0 new messages