Eclipse RCP:ClassNotFoundException或者如何使其他bundle加载我的类 [英] Eclipse RCP: ClassNotFoundException or How to make other bundle load my class

查看:831
本文介绍了Eclipse RCP:ClassNotFoundException或者如何使其他bundle加载我的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

详细信息:我正在尝试使用Jalapeno框架将我的RCP应用程序与Cache'数据库连接起来。连接建立后,我试图从表中完全获取所有数据,如Jalapeno手册:

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)

在terms.next();
我无法得到它...类DBClass的实例刚刚创建,但类不能加载。
然后我试图将这个代码放在简单的java应用程序(不是eclipse rcp)中,所有的都可以。所以我认为一些Eclipse部分阻止类加载。

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.

我也尝试在调用terms.next();

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();
}

并得到相同的错误。课无法加载。
那么,是已知的问题吗?有解决方案吗?
< ====
经过一些研究更新的问题:
如何使Jalapeno插件从我的插件加载类?

and got same error. class can not be loaded. so, is it known problem? is there a solution? =============================================== after some research updating the question: How to make Jalapeno plugin to load class from My plugin?

推荐答案

你可能想尝试好友类加载。有关Eclipse类加载的更多信息,Alex Blewitt在Eclipse中撰写了一个关于类加载系统的完美概述 here 。它几岁,但在很大程度上它仍然是相关的。

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.

好友类加载的主题是:


  • 一个插件声明它需要帮助加载类。通过声明其好友插件

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

,好友插件声明其好友政策

the buddy plugin declares its buddy policy

当正常加载机制失败时,Eclipse尝试使用您指定的好友类加载策略。

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

文件

并放置:

Eclipse-RegisterBuddy: id.of.jalepeno.plugin

在您的插件的manifest.mf中

in the manifest.mf of your plugin

这篇关于Eclipse RCP:ClassNotFoundException或者如何使其他bundle加载我的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆