admin管理员组文章数量:1290232
I writed and checked my js code in GWT. For checking I added my js code in (projectName).html file and it is worked.
But when I try added external js file I get an error:
WARN] 404 - GET <path to js file>someJsFile.js (127.0.0.1) 1452 bytes
Request headers
I added this line to (projectName).gwt.xml file:
<script src="src/main/resources/<projectName>/someJsFile.js"></script>
I writed and checked my js code in GWT. For checking I added my js code in (projectName).html file and it is worked.
But when I try added external js file I get an error:
WARN] 404 - GET <path to js file>someJsFile.js (127.0.0.1) 1452 bytes
Request headers
I added this line to (projectName).gwt.xml file:
<script src="src/main/resources/<projectName>/someJsFile.js"></script>
Share
Improve this question
asked Dec 2, 2013 at 6:10
P0ulBogdP0ulBogd
771 silver badge12 bronze badges
1
- you can add scripts into index page. – robert lennon Commented Dec 2, 2013 at 11:20
2 Answers
Reset to default 8To use this technique you have to place your someJsFile.js
in your public
folder so as the gwt piler copy it to the final folder where it places the html and js stuff.
If you are using maven you have to check if the resources plugin is copying this file to the war and in which path.
By the way, there are other techniques to insert external javascript in your document:
Placing the script tag in your .html file.
Using ScriptInjector.fromUrl().
A better approach is to use a TextResource and
ScriptInjector.fromString()
so as the piler reads the javascript file and includes the content in the final piled file.You can use gwtquery Ajax.getScript to get the script via ajax and inject it in the dom.
A new way, recently added to gwtquery, allows you to include your javascript as a JSNI block, so as the piler can optimize and obfuscate it.
I'd rather the last one because it offers much more advantages.
You can define in your_project.gwt.xml which folders to include as public. The paths should be relative to the xml:
resources/
|-your_project.gwt.xml
|-subfolder/
|-stuff/
|-images/
|-js/
|-someJsFile.js
In your xml add:
<public path="subfolder/stuff" />
This should copy images/ and js/ folders into your webapp directory and you can use sth like this for the js file
<script src="js/someJsFile.js"></script>
本文标签: javaadding external js in gwtStack Overflow
版权声明:本文标题:java - adding external js in gwt - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741493018a2381708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论