Gwt-exporter does not generate code (Java to Javascript)

I want to generate Javascript code from an existing Java project ( original question here ).

I am using GWT along with gwt-exportorter. After compiling GWT, 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;
    }
}

      

No link to RoadServer

anywhere in my directory war/

( grep -Ri RoadServer war/*

matches only files .class

). Also, to be sure, I opened the file war/GameEntryPoint.html

in my browser (Firefox) and Firebug sees it game_GameEntryPoint

as something that starts with game

.

Any idea why this isn't working?

PS I also tried to specify @Export

and @Export("RoadServer")

on @ExportPackage("game")

. Nothing works.

+2


source to share


1 answer


Yeah, it looks like it's a bug in ExporterUtil.exportAll()

. If a class has a non-empty constructor or does not have any methods, it is not exported. But if you add an empty constructor to the exported class and annotate the non-empty annotated constructor @Export

it starts working

You can also manually export the class:



public class GameEntryPoint implements EntryPoint {

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

}

      

But keep in mind that this way can sometimes export a class with errors

+3


source







All Articles