【问题标题】:Trying to integrate GWT into an OSGi bundle尝试将 GWT 集成到 OSGi 包中
【发布时间】:2011-05-15 19:35:04
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: java gwt osgi gwt-rpc equinox


    【解决方案1】:

    需要在 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 上运行!!

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • 感谢您的回复。我设法让它工作,结果我有一个我不知道的循环依赖,接口是从包外部访问的,由包含包装好的 GWT jar 的包访问。我通过将Eclipse-RegisterBuddy: GWT-bundle 行添加到我的ui 包的清单文件和Eclipse-BuddyPolicy: registered 行到GWT 包的清单来修复它。我会看看你链接的那个项目。
      猜你喜欢
      • 2014-04-26
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      相关资源
      最近更新 更多