How to ClientBundle in GWT?
Asked Answered
L

2

23

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.

Life answered 10/8, 2010 at 8:50 Comment(0)
S
24

I usually create a new package for resources (com.example.project.resource) and put the ClientBundle 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 your ClientBundle interface in com.example.project.resource and images in com.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 ;)

Suffruticose answered 10/8, 2010 at 12:5 Comment(2)
No matter how I try, I get: The method synchronous() from the type Resources refers to the missing type TextResourceAzral
@miroslavign: please open a new question, the comments section is not the place for troubleshooting new problems.Suffruticose
F
3

Similar to Igor's points:

com.yoursite.resources: YourClientBundle.java
com.yoursite.resources.css: YourCssResource.java
com.yoursite.resources.images: image files here

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.

Foulk answered 6/3, 2013 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.