Can't instantiate class from installed extensi

2019-05-26 03:04发布

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

2条回答
beautiful°
2楼-- · 2019-05-26 03:33

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.

查看更多
做个烂人
3楼-- · 2019-05-26 03:42

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?

查看更多
登录 后发表回答