Where do I put static files for GWT app? war folder or public folder?

前端 未结 3 1954
攒了一身酷
攒了一身酷 2020-12-05 19:35

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

3条回答
  •  臣服心动
    2020-12-05 20:06

    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

提交回复
热议问题