如何扩展非客户端GWT类

时间:2011-06-22 06:34:52

标签: gwt binding deferred

对于我的项目,我试图扩展未通过客户端模块继承的GWT类。 例如,我想创建一个com.google.gwt.resources.ext.ResourceGenerator的简单实现。

public class SimpleResourceGenerator implements ResourceGenerator

并使用而不是ClientBundle的默认@ResourceGeneratorType - BundleResourceGenerator

@ResourceGeneratorType(SimpleResourceGenerator.class)
    public interface Resources extends ClientBundle {

但未成功。

如果我将SimpleResourceGenerator类放在“client”包下,GWT编译器说:

         [ERROR] Line 11: No source code is available for type com.google.gwt.resources.ext.ResourceGenerator; did you forget to inherit a required module?
         [ERROR] Line 13: No source code is available for type com.google.gwt.core.ext.TreeLogger; did you forget to inherit a required module?
         [ERROR] Line 13: No source code is available for type com.google.gwt.resources.ext.ResourceContext; did you forget to inherit a required module?
         [ERROR] Line 13: No source code is available for type com.google.gwt.core.ext.typeinfo.JMethod; did you forget to inherit a required module?
         [ERROR] Line 14: No source code is available for type com.google.gwt.core.ext.UnableToCompleteException; did you forget to inherit a required module?
         [ERROR] Line 19: No source code is available for type com.google.gwt.resources.ext.ClientBundleFields; did you forget to inherit a required module?
         [ERROR] Line 36: No source code is available for type com.google.gwt.resources.ext.ClientBundleRequirements; did you forget to inherit a required module?

如果我将所有gwt-user和gwt-dev源链接到项目,我还有其他未解决的依赖项。

Loading inherited module 'com.google.gwt.user.User'
   Loading inherited module 'com.google.gwt.animation.Animation'
      Loading inherited module 'com.google.gwt.core.Core'
         Loading inherited module 'com.google.gwt.core.CrossSiteIframeLinker'
            [ERROR] Unable to load class 'com.google.gwt.core.linker.DirectInstallLinker'
java.lang.ClassNotFoundException: com.google.gwt.core.linker.DirectInstallLinker

我无法理解GWT编译器以及它在编译时如何解析类型。为什么它找到了一些GWT类而无法找到其他类。

我看到的唯一方法是编译SimpleResourceGenerator的模块重写

   <generate-with
    class="com.google.gwt.resources.rebind.context.StaticClientBundleGenerator">

    <!-- We have to specify on which types to execute the Generator -->
    <when-type-assignable
      class="com.google.gwt.resources.client.ClientBundle" />
   </generate-with>

来自继承的com.google.gwt.resources.Resources.gwt.xml和自己的生成器

  <generate-with
    class="com.example.gwt.SimpleBundleGenerator">
      <when-type-assignable
        class="com.google.gwt.resources.client.ClientBundle" />
  </generate-with>

并扩展com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator。

但对我来说似乎有点过于复杂。 是否有一种更简单的方法来扩展GWT类而不是通过生成器和代码替换的延迟绑定?

1 个答案:

答案 0 :(得分:1)

生成器不应包含在“client”包中,但它生成的java源应该包含。

“client”包用于gwt-compile,用于查找在将应用程序编译为javascript时应使用的java源文件,并使用Generator在编译时生成javasource文件。