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

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

问题描述

详细信息:我正在尝试使用 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();

at terms.next();

我根本无法得到它... DBClass 类的实例刚刚创建,但无法加载类.然后我尝试将此代码放在简单的 java 应用程序(不是 eclipse rcp)中,一切正常.所以我认为某些 Eclipse 部分阻止了类加载.

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

...并得到同样的错误.无法加载类.那么,这是一个已知问题吗?有解决办法吗?

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

经过一些研究更新问题:

After some research updating the question:

如何让 Jalapeno 插件从我的插件中加载类?

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

推荐答案

您可能想尝试伙伴类加载.有关 Eclipse 类加载的更多信息,Alex Blewitt 在 这里写了一篇关于 Eclipse 类加载系统的优秀概述.它已有几年历史了,但在大多数情况下它仍然具有相关性.

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

当常规加载机制失败时,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

在 Jalapeno 插件的 manifest.mf 文件中

in your Jalapeno plugin's manifest.mf file

然后放:

Eclipse-RegisterBuddy: id.of.jalepeno.plugin

在插件的 manifest.mf 中

in the manifest.mf of your plugin

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

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