问题描述
我想从现有的Java项目生成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;
导入org.timepedia.exporter.client.Exportable;
公共类RoadServer实现可导出{
int _index;
int _id;
public RoadServer(int index,int id){
this._id = id;
this._index = index;
code
$ b 没有提及 RoadServer
我的 war /
目录中的任何位置( grep -Ri RoadServer war / *
只匹配 .class
文件)。另外,为了确保,我在浏览器(Firefox)中打开了 war / GameEntryPoint.html
文件,而Firebug只能看到 game_GameEntryPoint
作为以游戏
开头的内容。
任何想法为什么这不起作用?
PS我还试着用 @ExportPackage指定 @Export
和 @Export(RoadServer)
游戏)
。没有任何作用。
解决方案 Aha,看起来像是 ExporterUtil.exportAll / code>。如果类具有非空的构造函数或没有任何方法,则不会导出它。但是,如果您向导出的类添加空的构造函数,并使用 @Export
注释注释非空构造函数,它将开始工作
您还可以手动导出类:
public class GameEntryPoint implements EntryPoint {
@覆盖
public void onModuleLoad(){
ExporterUtil.exportAll();
GWT.create(RoadServer.class); //强制导出道路服务器
}
}
但请注意,这种方式有时可以导出错误的类
I want to generate Javascript code from an existing Java project (original question here).
I use GWT in conjunction with gwt-exporter. After I GWT compile, none of my types appear in any of the generated code.
I have
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;
}
}
There is no reference to RoadServer
anywhere in my war/
directory (grep -Ri RoadServer war/*
matches only the .class
files). Also, just to be sure, I opened the war/GameEntryPoint.html
file in my browser (Firefox) and Firebug only sees game_GameEntryPoint
as something that starts with game
.
Any idea why this is not working?
P.S. I also tried specifying @Export
and @Export("RoadServer")
with @ExportPackage("game")
. Nothing works.
解决方案 Aha, so looks like it is some bug in ExporterUtil.exportAll()
. If class have non-empty constructor or doesn't have any methods it is not exported. But if you add an empty constructor to the exported class, and annotate non-empty constructor with @Export
annotation it starts working
Also you can manually export a class:
public class GameEntryPoint implements EntryPoint {
@Override
public void onModuleLoad() {
ExporterUtil.exportAll();
GWT.create(RoadServer.class); //forcing to export road server
}
}
But be aware that this way can sometimes export a class with errors
这篇关于gwt-exporter不生成代码(Java to Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!