Eclipse RCP: ClassNotFoundException or How to make

2019-02-15 21:02发布

Details: I'm trying to use Jalapeno framework to connect my RCP app with Cache' database. After connection established, I'm trying to get all data from table exactly like in Jalapeno manual:

if (objManager==null) return;
DBClass cortege = null;
try {
Iterator terms = objManager.openByQuery(DBClass.class, null, null);
System.out.println("terms ok");
while (terms.hasNext()){
    System.out.println("has next");
    cortege = (DBClass)terms.next();
}

this code compiling, running and trowing exception

java.lang.RuntimeException: myPluginId.views.DBClass
at com.intersys.objects.POJOIterator.next(POJOIterator.java:75)
   ...skip...
   Caused by: java.lang.ClassNotFoundException: myPlugin.views.DBClass
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at org.eclipse.core.runtime.internal.adaptor.ContextFinder.loadClass(ContextFinder.java:129)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.jalapeno.runtime.ObjectCopierToPojo.detach(ObjectCopierToPojo.java:76)
    at com.jalapeno.runtime.ObjectCopierToPojo.findPojo(ObjectCopierToPojo.java:472)
    at com.intersys.classes.CacheRootObject.detach(CacheRootObject.java:255)
    at com.intersys.classes.Persistent.detach(Persistent.java:567)
    at com.intersys.objects.POJOIterator.next(POJOIterator.java:59)

at terms.next();

I can't get it at all... instance of class DBClass was just created, but class cannot be loaded. then I've tried to place this code in simple java application (not eclipse rcp) and all went ok. so I think some Eclipse part blocking class loading.

also i've tried to load class before calling terms.next();

Bundle b = Platform.getBundle("myPluginId");
try {
b.loadClass("DBClass");
} catch (ClassNotFoundException e) {
System.out.println("no class");
e.printStackTrace();
}

...and got same error. Class can not be loaded. So, is it a known problem? Is there a solution?

Update

After some research updating the question:

How to make Jalapeno plugin to load class from My plugin?

2条回答
可以哭但决不认输i
2楼-- · 2019-02-15 21:39

You might want to try buddy classloading. For more info on Eclipse classloading, Alex Blewitt has written an excellent overview of the classloading system in Eclipse here. Its a few years old, but for the most part it is still relevant.

The jist of buddy classloading is this:

  • a plugin declares that it needs help loading classes. It does this by declaring its "buddy plugin"

  • the buddy plugin declares its buddy policy

  • when the regular loading mechanism fails, Eclipse tries to use the buddy classloading policies you have specified.

So in your case, try putting:

Eclipse-BuddyPolicy: registered

in your Jalapeno plugin's manifest.mf file

and put:

Eclipse-RegisterBuddy: id.of.jalepeno.plugin

in the manifest.mf of your plugin

查看更多
Bombasti
3楼-- · 2019-02-15 22:03

I am not sure, but maybe you have to export the package in which the classes are lying.

Select in the MANIFEST "Runtime" and add all packages

查看更多
登录 后发表回答