gwt-exporter doesn't generate code (Java to Javascript)

安稳与你 提交于 2019-12-10 23:56:19

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/10057844/gwt-exporter-doesnt-generate-code-java-to-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!