我想从现有 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")
。没有任何效果。
最佳答案
啊哈,看起来这是 ExporterUtil.exportAll()
中的一些错误。如果类有非空构造函数或没有任何方法,则不会导出。但是,如果您向导出的类添加一个空构造函数,并使用 @Export
注释来注释非空构造函数,它就会开始工作
您还可以手动导出类:
public class GameEntryPoint implements EntryPoint {
@Override
public void onModuleLoad() {
ExporterUtil.exportAll();
GWT.create(RoadServer.class); //forcing to export road server
}
}
但请注意,这种方式有时会导出有错误的类
关于java - gwt-exporter 不生成代码(Java 到 Javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10057844/