从类加载器中看不到Restlet jse2客户端资源接口

时间:2011-11-29 18:13:03

标签: maven osgi restlet

我在Google App Engine中为我的Restlet服务器提供了本教程:http://wiki.restlet.org/docs_2.0/13-restlet/21-restlet/318-restlet/303-restlet.html它适用于GWT客户端。

现在我正在尝试用OSGi和Restlet构建一个jse2桌面客户端。

OSGi包中Restlet客户端的代码与提供的tutorail相同。

当我启动OSGi Felix框架时,我也启动了org.restlet.jar包,它正在导出restlet框架包,并且我使用在toturail中给出的代码启动一个包:

ClientResource cr = new ClientResource("localhost:8888/contacts/123");
// Get the Contact object
ContactResource resource = cr.wrap(ContactResource.class);
Contact contact = resource.retrieve();

ContactResoure接口与bundle激活器位于同一个包中,但我仍然收到这条奇怪的消息: java.lang.IllegalArgumentException:interface nl.nhl.minor.crm.desktop.restlet.ContactResource不可见类加载器

这个问题与OSGi或Restlet有关吗?我该如何解决这个问题?

OSGi包的清单文件由maven包插件创建。

1 个答案:

答案 0 :(得分:0)

加载课程的正确方法很简单:

ClientResource cr = new ClientResource("http://127.0.0.1:8888/contacts/123");
Class<ContactResource> clazs = (Class<ContactResource>) cr.getClass().getClassLoader().loadClass("your.package.name.ClassName");
cr.wrap(clazs);

此解决方案为您提供了另一个问题,该类未由org.restlet包导入。

有关该问题的问题,请参阅import package without edit the manifest file in org.restlet