简体   繁体   中英

Javascript library in gwt

How to aadd javscript library from file to gwt?

I tried:

  • ScriptInjector - exception is thrown: onModuleLoad() threw an exception

    Exception while loading module modue.name. See Development Mode for details. java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at ...

  • own script injector ( source )

    Problem: content of the library is added to the source code, but cannot be accessible any part of the source code.

Can sb give an example?

Solution for your problem with the 2nd option (own script injector)

Problem: content of the library is added to the source code, but cannot be accessible any part of the source code.

You have to use JSNI to be able to use the javascript-methods of the added library in gwt.

Here is a little example for executing a javascript-method from java:

Let's say the added javascript-library contains this method:

function say(message) {
    window.alert(message);
}

Create a java class JavascriptLibrary.java:

public final class JavascriptLibrary {

    public static native void sayJava(String message) /*-{
        $wnd.say(message);
    }-*/;

}

Now you can execute this method with JavascriptLibrary.sayJava("Hello");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM