Jamesy82
Jamesy82

Reputation: 379

Can't instantiate class from installed extension when run via OSGI

So, I have an installed extension (see http://docs.oracle.com/javase/tutorial/ext/basics/index.html) which I can see in Eclipse.

I've written a simple rcp application that tries to create an instance of a class in this extension. However, although everything compiles ok, I'm getting a NoClassDefFoundError when creating the instance.

I'm assuming this has something to do with OSGi because I can run a simple java application that creates the instance fine.

Any suggestions would be really appreciated.

Thanks

Upvotes: 2

Views: 969

Answers (2)

Jamesy82
Jamesy82

Reputation: 379

I've found another solution which is to set the parent classloader to the 'ext' classloader using the arg

osgi.parentClassloader=ext

Not sure yet the implications of such a change other than I now don't get the error.

Upvotes: 3

earcam
earcam

Reputation: 6682

As your extension's classes are being provided by the JRE, they need to be exported by the OSGi framework's system bundle.

This can be achieved by adding the package(s) to the org.osgi.framework.system.packages.extra property (you can set this as a system property and it will be passed into the framework).

Once this is done and your consuming bundle has those packages listed in the Import-Package entry of it's MANIFEST.MF, you should be able access the classes.

JRE extensions are almost the antithesis of OSGi - I'm curious to know why you're doing this?

Upvotes: 2

Related Questions