I have some JavaScript files, a main HTML file, a main CSS file, and some CSS files that get imported into the main one.
I understand that I can put static files in two places: a) the 'war' folder; or b) the 'public' folder.
Where is the best place to put my static files? Are the two locations treated differently? Is there a 'best practice' on this issue?
The difference between the 2 locations is that files in the public folders are copied by the gwt compiler to the 'your module' folder in the 'war' folder. This is means if you deploy the 'war' (for example via the google plugin to the google appengine) the files from the 'public' folder are not at the toplevel.
For example, if you have an index.html in the 'public' folder with gwt module named 'mymodule' and you deploy it to www.example.com it looks as follows, you need to access it via:
If you have the index.html in the 'war' folder, you get:
Summarizing. Your landing page should be in the 'war' folder. Resource files used by the landing page can also be stored here (css, images). Any other resource file that is referred to in any gwt module file (or code, like images) should be stored in the 'public' folder related to the gwt module.
As I see it, it depends on your requirements, but let's start at a speaking example first ...
I find the documentation (should be GWT 2.6.0) about this to be incorrect or at least incomplete/confusing. As I see it (I am not a guru so please correct me if my investigations are wrong!) I am looking at the following example proj structure
Imagine we may (or may not) need to reference such resources in some
AppClientBundle
interface (or other application reference context):Then it seems to depend on your Requirements, e.g.:
AppClientBundle
interface via@Source
annotationsfoo2.png
vs.img/foo1.png
http://host1/gwtapp1/foo4.png
vs.http://host1/gwtapp2/foo4.png
http://host1/gwtapp1/foo4.png
vs.http://host1/foo6.png
Here's what one can do (Possibilities) and it's implications regarding R.* above:
my.gwtproj.client
(here e.g.foo1.png
)@Source("img/foo1.png")...
works finepublic
folder (in my casemy.gwtproj.public
), but creating it as a package in Eclipse does not me allow this (sincepublic
is a reserved Java key word, but creating it via theNavigator
view works)@Source
above does not work (likely because it's an issue with the relativeAppClientBundle
file system location)public
foldermyproj/war
, e.g.projdir/war/foo6.png
@Source
http://host1/foo6.png
myproj/war
, e.g.projdir/war/img/foo5.png
@Source("img/foo5.png")
would not work anymoreThe new way of working in GWT is to use the war folder.
But, if you project is a reusable widget library which is used in a GWT application then you should put the resources in the public folder. The compiler will make sure that the files are automatically included in the generated package.