I recommend using ScriptInjector instead of putting the script tag in the module's XML file because it allows you to use SuperDevMode (xsilinker doesn't allow for script tags in the module's xml file). If you have a maven project structure it like this:
src/main/java
- my.company.widgets.pubnub.client
- Some3rdPartyWrapper.java
src/main/resources
- my.company.widgets.pubnub
- PubNub.gwt.xml
- my.company.widgets.pubnub.client.resources
- pubnub.js
If you have a non-maven project use following stucture:
src/
- my.company.widgets.pubnub
- PubNub.gwt.xml
- my.company.widgets.pubnub.client
- PubNubWrapper.java
- my.company.widgets.pubnub.client.resources
- pubnub.js
Now create a ClientBundle :
interface JsClientBundle extends ClientBundle {
JsClientBundle INSTANCE = GWT.create(JsClientBundle.class);
@Source("resources/pubnub.js")
TextResource pubnubjs();
}
and then add following two methods to your wrapper class (PubNubWrapper.java)
private void injectScript() {
if (!isInjected()) {
ScriptInjector.fromString(JsClientBundle.INSTANCE.pubnub().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
}
}
private native final boolean isInjected() /*-{
if (!(typeof $wnd.PubNub === "undefined") && !(null===$wnd.PubNub)) {
return true;
}
return false;
}-*/;
You have to call injectScript() at some point (for example in your constructor or in the onAttach/onLoad method).
Of course you can also load your script asynchronously (can be done with ScriptInjector)