【问题标题】:gwt-exporter doesn't generate code (Java to Javascript)gwt-exporter 不生成代码(Java 到 Javascript)
【发布时间】:2012-04-20 22:03:32
【问题描述】:

我想从现有的 Java 项目 (original question here) 生成 Javascript 代码。

我将 GWT 与 gwt-exporter 结合使用。在我 GWT 编译之后,我的类型都没有出现在任何生成的代码中。

我有

GameEntryPoint.java

package game.client;

import org.timepedia.exporter.client.ExporterUtil;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JavaScriptObject;

public class GameEntryPoint implements EntryPoint {

    @Override
    public void onModuleLoad() {
        ExporterUtil.exportAll();
    }

}

RoadServer.java

package game.client;

import org.timepedia.exporter.client.Exportable;

public class RoadServer implements Exportable {
    int _index;
    int _id;
    public RoadServer(int index,int id){
        this._id=id;
        this._index=index;
    }
}

在我的war/ 目录中的任何地方都没有对RoadServer 的引用(grep -Ri RoadServer war/* 仅匹配.class 文件)。此外,为了确定起见,我在浏览器 (Firefox) 中打开了 war/GameEntryPoint.html 文件,而 Firebug 仅将 game_GameEntryPoint 视为以 game 开头的内容。

知道为什么这不起作用吗?

附:我还尝试用@ExportPackage("game") 指定@Export@Export("RoadServer")。没有任何效果。

【问题讨论】:

    标签: java javascript gwt code-generation


    【解决方案1】:

    啊哈,看来这是ExporterUtil.exportAll() 中的一些错误。如果类具有非空构造函数或没有任何方法,则不会导出。但是如果你在导出的类中添加一个空的构造函数,并用@Export注解非空的构造函数,它就会开始工作

    你也可以手动导出一个类:

    public class GameEntryPoint implements EntryPoint {
    
        @Override
        public void onModuleLoad() {
            ExporterUtil.exportAll();
            GWT.create(RoadServer.class); //forcing to export road server
        }
    
    }
    

    但请注意,这种方式有时会导出错误的类

    【讨论】:

    • 谢谢。我必须在构造函数和类上都添加 @Export 注释才能使它工作,但它终于做到了。我还遇到了具有返回自定义类型数组的方法的类的问题。更改这些以填充给定数组也解决了该问题。遗憾的是 gwt-exporter 上的文档没有列出这些问题。
    • 可导出类需要一个无参数构造函数,或者一个接受 JavaScriptObject 的构造函数。如果它无法导出您因此标记为@Export 的类,它会给出编译时错误或警告,那就太好了。
    猜你喜欢
    • 2011-08-23
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 2012-07-06
    • 2019-03-25
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多