GWT-exporter. Working example

2019-07-09 01:43发布

问题:

I have a Java lib and I need to convert it to JS. I found the solution GWT to create utility javascript library to use gwt-exporter. I never used GWT before. I tried GWT-exporter. Getting started but it's not clear how to use it. Simply how to run the project to generate JS?

pom.xml

<dependencies>
    <dependency>
        <groupId>org.timepedia.exporter</groupId>
        <artifactId>gwtexporter</artifactId>
        <version>2.4.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Java class:

import org.timepedia.exporter.client.ExporterUtil;

public class JS implements EntryPoint {
public void onModuleLoad() {
    // Export all Exportable classes
    ExporterUtil.exportAll();
}

}

Where to find dependency for EntryPoint?

Maybe someone can share working example?

回答1:

https://code.google.com/p/gwt-exporter/wiki/GettingStarted is poor. To compile JS I added gwt-maven-plugin.

Also I created .gwt.xml file with description of my module.

Following dependency is mandatory

    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <scope>provided</scope>
    </dependency>


回答2:

Apart from adding gwt-exporter to your class-path, did you update your module file (application_name.gwt.xml) inheriting the gwt-exporter dependency?.

If so, in this file you should have an entry-point tag pointing to the class to run when the app starts. Open that java file and add the exportAll call.

Finally visit all the classes/methods you want to make available in javascript and annotate them appropriately like in the getting started page is indicated