1

我正在尝试将 GWT 与 OSGi (Equinox) 集成,以为我的模块化系统的其余部分提供基于 Web 的 UI。到目前为止,我已经设法将 GWT servlet 嵌入到 OSGi 模块中。

我正在使用 Eclipse GWT 插件生成的 GWT 示例代码项目,它由 3 个包组成:客户端、服务器和共享。服务器包(ui.server.GreetingServiceImpl)中的类实现了客户端包(ui.client.GreetingService)中的接口,它们都在同一个包中。

当我尝试从客户端网页进行远程过程调用时,出现错误:

IncompatibleRemoteServiceException: Could not locate requested interface 'ui.client.GreetingService' in default classloader

我收集到类加载器没有找到该类,但我不知道如何解决这个问题。我可以通过要求或导入其他包中的类来访问它们,但不能访问与实现类位于同一包中的接口。谁能指出我正确的方向?我已经在谷歌上搜索了几个小时。

4

2 回答 2

2

需要从 GreetingServiceImpl 上的 HttpServlet 覆盖方法“服务”:

@Override 
protected void service(HttpServletRequest req, HttpServletResponse resp) 
        throws ServletException, IOException { 
    // Cache the current thread 
    Thread currentThread = Thread.currentThread(); 
    // We are going to swap the class loader 
    ClassLoader oldContextClassLoader = 
    currentThread.getContextClassLoader(); 
    currentThread.setContextClassLoader(this.getClass().getClassLoader()); 
    super.service(req, resp); 
    currentThread.setContextClassLoader(oldContextClassLoader); 
} 

因此,该应用程序在 Equinox 上运行!

于 2011-05-26T10:52:54.537 回答
0

IncompatibleRemoteServiceException 意味着来自 GUI 的 RPC 调用没有找到 @RemoteService 注解指定的接口。

你能用源代码发布你的项目吗?

顺便说一句,你也可以看看这个项目: http ://code.google.com/p/gwt-in-osgi/

于 2011-05-16T06:31:37.400 回答