The easiest way to export a gwt project to js is using gwt-exporter. Gwtexporter allows to export any gwt project without writing a single line of jsni code and it has plenty of features which allows to customize classes and methods exposed to js, and even it could produce the documentation for your js api.
In your case, implement the Exportable
interface in the class with your static method, and annotate your method.
public class MyClass implements Exportable {
@Export("$wnd.testMe")
public static String testMe(Object obj) {
return "Response to " + obj.toString();
}
}
Then you have to call the exportAll()
method in your entry point and leave the gwt compiler and gwtexporter generator do their magic
public void onModuleLoad() {
ExporterUtil.exportAll();
}
Here you have a tutorial of how to export a gwt-library to js, although the documentation of the project is quite good.
Some of the projects using this technique are chronoscope, gwtupload(jsupload) and gwtquery(jsquery).