如何在 GWT 中进行 ClientBundle?
我是第一次使用 GWT ClientBundle。我编写了扩展它的接口,这里是代码:
package edu.etf.fuzzy.client.login;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
public interface Resources extends ClientBundle {
@Source("logo_federacija.jpg")
ImageResource logo();
@Source("shim.gif")
ImageResource shim();
}
我的问题是:如何知道可以在哪里找到这些资源(在本例中为图像)。我应该把它们: a)与接口在同一目录中 - (丑陋)? b) 在某个永远无法更改的特定目录中? c)在我想要的目录中,但应该有机制来指定它 - (会很棒)?
谢谢。
I am using GWT ClientBundle for the first time. I wrote interface that extends it and here is the code:
package edu.etf.fuzzy.client.login;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
public interface Resources extends ClientBundle {
@Source("logo_federacija.jpg")
ImageResource logo();
@Source("shim.gif")
ImageResource shim();
}
My question is: How do I tell where exactly these resources (images in this case) can be found. Should I put them:
a) in the same directory as interface - (ugly)?
b) in some specific directory that never can be changed ?
c) in directory that I want, but there should be mechanism to specify it - (would be great)?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常为资源创建一个新包 (
com.example.project.resource
),并将ClientBundle
接口和适当的资源放在那里(一起,就像在一个目录中一样) - 这是一个java文件加上一堆图像,不需要进一步分离,恕我直言。至于资源的路径 - 您可以通过 @Source("path") 注释传递它们。例如,如果您的
ClientBundle
接口位于com.example.project.resource
中,图像位于com.example.project.images
中,那么你会写@Source("../images/shim.gif")
。您可能可以使用绝对路径,但请确保将它们存储在静态变量中并在资源之间共享,以便可以轻松覆盖它;)I usually create a new package for resources (
com.example.project.resource
) and put theClientBundle
interface and the appropriate resources there (together, as in in one directory) - it's one java file plus a bunch of images, no need for further separation, IMHO.As for the paths to the resources - you can pass them via
@Source("path")
annotation. For example, if you have yourClientBundle
interface incom.example.project.resource
and images incom.example.project.images
, then you'd write@Source("../images/shim.gif")
. You could probably use absolute paths, but make sure you store them in a static variable and share amongst the resource, so it can be easily overridden ;)与 Igor 的观点类似:
这里的关键是,如果您不消耗资源(CSS/图像/文本),GWT 编译器将忽略它。这可以防止战争膨胀,因为您的应用程序获得持有者并且您拥有数百张图像并且不确定哪些已使用,哪些未使用。
如果您使用将所有内容删除到 public/images 文件夹中的选项,那么所有项目都将包含在您的应用程序战争中,无论它们是否被使用。
Similar to Igor's points:
The key here is that if you don't consume a resource (CSS/Image/Text), the GWT compiler will ignore it. This prevents war bloat as your application gets holder and you've got hundreds of images and are not sure which are used and which are not.
If you use the option of dropping everything in the public/images folder, then all of the items will be included in your application war, regardless of whether they're used.