我应该将 GWT 应用程序的静态文件放在哪里? war 文件夹还是 public 文件夹?
我有一些 JavaScript 文件、一个主 HTML 文件、一个主 CSS 文件以及一些导入到主文件中的 CSS 文件。
我知道我可以将静态文件放在两个地方:a)“war”文件夹;或 b) “公共”文件夹。
放置静态文件的最佳位置在哪里?这两个地方的待遇有区别吗?关于这个问题有“最佳实践”吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这两个位置之间的区别在于公共文件夹中的文件由 gwt 编译器复制到“war”文件夹中的“your module”文件夹。这意味着如果您部署“war”(例如通过谷歌插件到谷歌应用程序引擎),“public”文件夹中的文件不会位于顶层。
例如,如果“public”文件夹中有一个名为“mymodule”的 gwt 模块的 index.html,并将其部署到 www.example.com,它看起来如下,您需要通过以下方式访问它:
如果您有索引在“war”文件夹中的 .html 中,您会得到:
总结。您的目标网页应位于“war”文件夹中。登陆页面使用的资源文件也可以存储在这里(css、图像)。任何 gwt 模块文件(或代码,如图像)中引用的任何其他资源文件应存储在与 gwt 模块相关的“public”文件夹中。
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.
GWT 中的新工作方式是使用 war 文件夹。
但是,如果您的项目是在 GWT 应用程序中使用的可重用小部件库,那么您应该将资源放在公共文件夹中。编译器将确保这些文件自动包含在生成的包中。
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.
在我看来,这取决于您的要求,但让我们首先从一个口语示例开始......
我找到 文档(应该是 GWT 2.6.0)对此不正确或至少不完整/令人困惑。正如我所见(我不是专家,所以如果我的调查有误,请纠正我!)我正在查看以下示例项目结构
想象一下我们可能(或可能)不需要)需要在某些
AppClientBundle
接口(或其他应用程序引用上下文)中引用此类资源:那么它似乎取决于您的要求,例如:
AppClientBundle
界面中通过@Source
注释foo2.png
与img/foo1.png
http://host1/gwtapp1/foo4.png
与http://host1/gwtapp2/foo4.png
http://host1/ gwtapp1/foo4.png
与http://host1/foo6.png
以下是人们可以做的事情(可能性)及其对 R 的影响.* 上面:
my.gwtproj 下.client
(此处例如foo1.png
)@Source("img/foo1.png")...
工作正常public
文件夹(在我的例子中my.gwtproj.public
),但是将其创建为Eclipse 中的包不允许这样做(因为public
是保留的 Java 关键字,但通过Navigator
视图创建它是可行的)@Source
就不起作用(可能是因为相对AppClientBundle
文件系统位置存在问题)public
文件夹来实现myproj/war<下/code>
,例如- 这样就可以在注释中使用/找到它,例如
- 并且可以通过例如
projdir/war/foo6.png
@Source
http://host1/foo6.png
在应用程序本身外部引用它
myproj/war
下,例如projdir/war/img/foo5.png
@Source("img/foo5.png")
将不再起作用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 anymore