【问题标题】:GWT compilation error, images and deferred bindingGWT 编译错误、图像和延迟绑定
【发布时间】:2014-09-11 23:07:16
【问题描述】:

和三个朋友,我正在用 gwt (2.6) 开发一个应用程序。几周前,我们开始使用超级开发模式。一切都很好,除了我们两个不能使用 ImageBundles。它始于我想包含一个 SuggestBox,它显然会加载一些图像。 GWT 编译失败。我用谷歌搜索了很多,但我无法修复它,所以我开始做其他事情:使用 ImageResourceBundle 加载一些图像。 GWT 编译失败。同样的错误。解决方法:不使用 ImageResourceBundle 加载图像。真正奇怪的是:我们中的两个人使用 Windows,一个使用 ubuntu,而我使用的是 mac。编译适用于 ubuntu 和其中一台 Windows 机器。在其他机器上,无论我们尝试什么,编译错误始终保持不变:

Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   Computing all possible rebind results for 'com.google.gwt.user.client.ui.MenuBar.Resources'
      Rebinding com.google.gwt.user.client.ui.MenuBar.Resources
         Invoking generator com.google.gwt.resources.rebind.context.InlineClientBundleGenerator
            [ERROR] No @com.google.gwt.resources.ext.ResourceGeneratorType was specifed for type com.google.gwt.resources.client.ImageResource or its supertypes
   [ERROR] Errors in 'com/google/gwt/user/client/ui/MenuBar.java'
      [ERROR] Line 212: Failed to resolve 'com.google.gwt.user.client.ui.MenuBar.Resources' via deferred binding
   Computing all possible rebind results for 'com.google.gwt.user.client.ui.impl.ClippedImageImpl.Template'
      Rebinding com.google.gwt.user.client.ui.impl.ClippedImageImpl.Template
         Invoking generator com.google.gwt.safehtml.rebind.SafeHtmlTemplatesGenerator
            Constructing interface com.google.gwt.user.client.ui.impl.ClippedImageImpl.Template
               Generating method body for image()
                  [ERROR] Required annotation @Template not present on interface method public abstract com.google.gwt.safehtml.shared.SafeHtml image(com.google.gwt.safehtml.shared.SafeUri clearImage, com.google.gwt.safecss.shared.SafeStyles style)
   [ERROR] Errors in 'com/google/gwt/user/client/ui/impl/ClippedImageImpl.java'
      [ERROR] Line 104: Failed to resolve 'com.google.gwt.user.client.ui.impl.ClippedImageImpl.Template' via deferred binding
   Computing all possible rebind results for 'com.google.gwt.user.client.ui.impl.ClippedImageImpl.DraggableTemplate'
      Rebinding com.google.gwt.user.client.ui.impl.ClippedImageImpl.DraggableTemplate
         Invoking generator com.google.gwt.safehtml.rebind.SafeHtmlTemplatesGenerator
            Constructing interface com.google.gwt.user.client.ui.impl.ClippedImageImpl.DraggableTemplate
               Generating method body for image()
                  [ERROR] Required annotation @Template not present on interface method public abstract com.google.gwt.safehtml.shared.SafeHtml image(com.google.gwt.safehtml.shared.SafeUri clearImage, com.google.gwt.safecss.shared.SafeStyles style)
   [ERROR] Errors in 'com/google/gwt/user/client/ui/impl/ClippedImageImpl.java'
      [ERROR] Line 96: Failed to resolve 'com.google.gwt.user.client.ui.impl.ClippedImageImpl.DraggableTemplate' via deferred binding
[ERROR] Compiler returned false

我真的不知道该怎么办。我们检查了 eclipse 和 tomcat 中的几乎所有设置/配置文件。这都一样。有谁知道在哪里看?也许我在寻找错误的地方。我很感激你能给我的任何帮助。

附加信息(更新)

  • 使用 ant 构建应用程序时,gwt-compile 运行时不会出错。
  • 我们使用没有 google 插件的 eclipse。
  • 在开发模式下,Web 应用程序通过 tomcat7 启动。
  • 在 Web 应用程序中调用超级开发模式(在 Servlet.init() 中)。因此,我们必须将 gwt-dev jar 添加到 tomcat 启动器的类路径中。
  • 在我们的 gwt 源代码中包含 new SuggestBox() 的任何位置会导致某些机器上的 gwt-compile-error。没有new SuggestBox(),一切都会到处编译。

我认为这是一个类路径或 gwt-compile-sourcepath 问题。但我们在使用的不同机器上没有发现任何差异。

【问题讨论】:

  • 将 logLevel 设置为 TRACE。您将获得有关该错误的更多信息。
  • 启动应用程序时使用哪些参数?

标签: eclipse tomcat gwt gwt-super-dev-mode


【解决方案1】:

使用 ant 构建应用程序时,gwt-compile 运行时不会出错。

1) 所以如果你比较你编译它的方式和 ant 编译它的方式,你就会发现根本原因。

2) 如果您没有发现任何区别,或者您不知道 Eclipse(或您使用的任何工具)如何编译您的应用程序,请尝试以这种方式编译它(我们可以称之为 真正的纯 dzen 方式没有任何 eclipse、ant、maven 或其他第三方“助手”):

java -cp gwt-dev.jar;gwt-user.jar;validation-api-1.0.0.GA.jar;validation-api-1.0.0.GA-sources.jar;any/other/lib.jar;path/to/your/module/source/code com.google.gwt.dev.Compiler moduleName

如果您的 .gwt.xml 描述符位于 com/your/gwt/module/MyModule.gwt.xml 下,您应该使用 com.your.gwt.module.MyModule 作为 moduleName

【讨论】:

  • 现在,Web 应用程序不再在我们的 Web 应用程序的单独线程中运行代码服务器,而是创建了一个新的 Java-Process 来运行 CodeServer。
【解决方案2】:

由于您没有包含任何代码,因此很难猜测可能出了什么问题,但这里有一些可能的原因:

零参数构造函数

这是我阅读的文章中提到最多的一篇(参考文献如下),似乎正是您遇到的问题,但我不得不承认我不知道为什么会发生这种情况一些你的队友(也许它只是在某些虚拟机或类似的情况下需要)。

这可能是一个延迟绑定问题(根据您发布的编译器日志),因此您应该检查您的所有 POJO(普通旧 java 对象)类是否具有用于延迟加载的零参数构造函数。

Failed to resolve class via deferred binding

注释冲突

也许你有一些注释放错了,如下所述:

Deferred binding failed GWT using uibinder

@UiConstructor 和 @UiFactory 等一些注解不能很好地结合使用,并且(即使在这种情况下它们实际上并不冲突)可能会导致类似的问题。

参考资料及更多

【讨论】:

  • 感谢您的帮助,我已经用更多信息更新了原始描述。
  • @Witek 太好了,能否请您包含 SuggestBox 类的代码(至少部分;构造函数)?
  • 它是默认的 com.google.gwt.user.client.ui.SuggestBox。不是我们的代码。 SuggestBox 只是一个例子。它接缝,当我们使用任何本身使用图像(或图像包)的 GWT 组件时,我们会收到错误。
  • @Witek 在编译器日志中我看到了两种不同类型的错误作为错误源(其他可能只是某种堆栈跟踪?):1.)没有 com.google。 gwt.resources.ext.ResourceGeneratorType 被指定为类型 com.google.gwt.resources.client.ImageResource 或其超类型和 2.) 接口方法公共抽象 com.google.gwt.safehtml.shared.SafeHtml 上不存在必需的注释模板image(com.google.gwt.safehtml.shared.SafeUri clearImage, com.google.gwt.safecss.shared.SafeStyles style) 所以这可能是缺少注释或类似问题的问题。
【解决方案3】:

如果你使用 Maven,你可以很容易地用 mvn compile 做一个 javac,然后你可以运行 mvn gwt:compile。这些讨厌的错误会消失。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-09
    • 2014-12-17
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 1970-01-01
    相关资源
    最近更新 更多