There is no way using the .gwt.xml
file, you can though, do it in your code visiting all '<script>' tags of your document and checking whether the src
attribute matches your library name. Then you can inject the script using the ScriptInjector
helper.
NodeList<Element> scripts = Document.get().getElementsByTagName("script");
for (int i = 0; i < scripts.getLength(); i++) {
Element e = scripts.getItem(i);
if (e.getAttribute("src").matches(".*myjslib.js")) {
return;
}
}
ScriptInjector.fromUrl("myjslib.js").inject();
[EDITED]
As @ThomasBroyer says in his first comment, the easiest way to load the script is adding a <script>
tag in the head of your page. And the most reliable way to be sure that the script has been loaded before using it in GWT is knowing that some property has been set in the window object. For instance if you want to load jquery.js you can test whether $wnd.jQuery is defined.
[EDITED]
In your Javascript libary include something like:
window.myjslib = true;
In your Java code:
public void OnModuleLoad() {
if (isMyJsLibLoaded() == false) {
ScriptInjector.fromUrl("myjslib.js").inject();
}
}
private native boolean isMyJsLibLoaded() /*-{
return !!$wnd.myjslib;
}-*/;