【问题标题】:GWT : How to use beans from separate module?GWT:如何使用来自单独模块的 bean?
【发布时间】:2015-04-11 09:27:14
【问题描述】:

我正在开发一个带有单独模块的项目。 adminsbackendusersclientcore 之间的共享 DAO 层 后端和客户端
backend 模块使用 GWT,client 使用 Spring MVC。在 backend 模块中,core 模块被 deployment assembly 包含。我的服务器端,DAO 是由 Spring 注入的。
core 模块中创建的所有 bean(POJO)。我的问题是我想在我的 gwt 项目(backend 模块)中或在使用 RPC 调用时使用来自 core 模块的这些 bean。
我尝试作为How can share bean from external library to GWT client? 问题的答案,但还不满意。我得到以下错误

没有可用于类型的源代码 com.mycom.core.business.bean.TestBean; [错误] 提示:检查 来自您的模块的继承链;它可能没有继承 所需模块或模块可能未添加其源路径条目 正确的

这是我努力的代码...

TestBean.java

public class TestBean {
private int id;

public final int getId() {
    return id;
}

public final void setId(int id) {
    this.id = id;
}
}

beans.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module>
   <inherits name='com.google.gwt.user.User'/>
   <source path="com.mycom.core.business.bean.TestBean"/>
</module>

在我的 App.gwt.xml 中将 beans.gwt.xml 继承为 &lt;inherits name='com.mycom.backend.beans'/&gt; 。我错过了什么?

编辑:添加示例项目文件

现在我创建并上传了示例模块。您可以从 google-drive URL 下载它。这个存档文件包含 backendcore 模块。

  • core 模块从 Eclipse IDE 创建为简单的 java 项目。

  • backend 模块由 gwt-ecliplse 插件创建(2.7 gwt 版本并包含生成的代码)并添加 Dynamic Web Module 2.5 项目面。

最后,我使用 GWT-Eclipse 插件 构建和运行,您可以检查屏幕截图

类路径

源查找路径

模块

以下是我控制台中的错误日志

Super Dev Mode starting up
workDir: /var/folders/mt/5287l4j94jd9rfqwqdqxr9zw0000gq/T/gwt-codeserver-7296341534601698800.tmp
Loading Java files in com.mycom.backend.App.
Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
Finding entry point classes
  Tracing compile failure path for type 'com.mycom.backend.client.Backend'
     [ERROR] Errors in 'file:/Applications/springsource/workspace/backend/src/com/mycom/backend/client/Backend.java'
        [ERROR] Line 41: No source code is available for type com.mycom.core.business.bean.TestBean; did you forget to inherit a required module?
  [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
[WARN] Server class 'com.google.gwt.dev.shell.jetty.JDBCUnloader' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/Users/cataclysm/Desktop/eclipse%20(Luna)/Datas/gwt-2.7.0/gwt-dev.jar' to the web app classpath for this session
For additional info see: file:/Users/cataclysm/Desktop/eclipse%20(Luna)/Datas/gwt-2.7.0/doc/helpInfo/webAppClassPath.html

【问题讨论】:

    标签: java gwt javabeans gwt-rpc


    【解决方案1】:

    核心模块的源路径应该可以被 GWT 编译过程访问。确保将其添加到类路径或源查找路径中。

    【讨论】:

    • 正如我所描述的,我通过部署程序集添加了我的core模块。所以这可以在 backend 模块 > Java Build Path > Projects 、 Order 和 Export 选项卡上看到。我还将库选项卡中的类文件夹添加到我的 bean 文件夹中,但错误仍然存​​在。
    • 你是如何构建你的应用模块的?
    • 我使用 GWT Eclipse 插件构建和运行,而不是使用 maven。
    • 好的,你得到一个运行配置。您可以检查该运行配置的类路径吗?在我的情况下,我需要在那里显式添加文件夹,以便编译器获取源代码。
    • Yes yes .. 这些也包含在 User Entries 下的部署程序集中。
    【解决方案2】:

    beans 的模块文件应位于core 文件夹/库中。 尝试将其移至core/src/com/mycom/ 并在beans.gwt.xml 中相应地修改源路径:

    <source path="core"/>
    

    记住,它是相对于模块文件的。

    然后修改App.gwt.xml中的条目:

    <inherits name='com.mycom.beans'/>
    

    我不熟悉部署程序集,但请确保 beans.gwt.xml 存在于生成的库 jar 中(或与源一起复制)。

    【讨论】:

    • 你不知道我有多感谢你。非常感谢您的帮助。
    • 很高兴我能提供帮助 - 在我建立自己的项目时不得不经历同样的考验,所以我知道这有多麻烦 :)
    猜你喜欢
    • 2017-04-22
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多