Question

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?

Was it helpful?

Solution

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:

www.example.com/mymodule/index.html

If you have the index.html in the 'war' folder, you get:

www.example.com/index.html

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.

OTHER TIPS

The 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.

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

myproj/
  src/my/gwtproj/
     client/
       img/
         foo1.png
       AppClientBundle.java
       foo2.png
     public/
       img/
         foo3.png
       foo4.png
  war/
    img/foo5.png
    foo6.png
  .classpath
  .project

Imagine we may (or may not) need to reference such resources in some AppClientBundle interface (or other application reference context):

interfaces AppClientBundle extends ClientBundle {

  @Source("img/foo1.png")
  ImageResource fooImg();
}

Then it seems to depend on your Requirements, e.g.:

  • R.a) these resources (like images) are refered to in the application code, e.g. in our AppClientBundle interface via @Source annotations
  • R.b) these resources are to be grouped by folders, e.g. foo2.png vs. img/foo1.png
  • R.c) these resources should be available outside some specific application URL context path, e.g. if used as widget library, e.g. http://host1/gwtapp1/foo4.png vs. http://host1/gwtapp2/foo4.png
  • R.d) these resources need to be application-independently (e.g. externally) URL-referenced, e.g. http://host1/gwtapp1/foo4.png vs. http://host1/foo6.png

Here's what one can do (Possibilities) and it's implications regarding R.* above:

  • P.1) (generally recommended as I see it) put nicely folder-structured resources under my.gwtproj.client (here e.g. foo1.png)
    • this way @Source("img/foo1.png")... works fine
    • in the docs above they speek about some public folder (in my case my.gwtproj.public), but creating it as a package in Eclipse does not me allow this (since public is a reserved Java key word, but creating it via the Navigator view works)
      • however, this way the @Source above does not work (likely because it's an issue with the relative AppClientBundle file system location)
      • nevertheless if the resource should be publicly available under the application context one may have to do it via this public folder
  • P.2) put "ungrouped" resources directly under myproj/war, e.g. projdir/war/foo6.png
    • this way it can be used/found within annotations, e.g. @Source
    • and it can be referenced outside the application itself via e.g. http://host1/foo6.png
  • P.3) put folder-structured resources under myproj/war, e.g. projdir/war/img/foo5.png
    • in contrast to P.2) @Source("img/foo5.png") would not work anymore
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top