6

I have the following line of code to set the URL of an image I want to display

img.setUrl("images/img1.jpg");

Where should I place my images folder in order for it to get picked up correctly. Currently I have it in my WEB-INF folder but this does not appear to work. I get the error on my console "WARNING: No file found for: /images/img1.jpg" I created my project using Eclipse and I have not changed any folder structure.

1

4 Answers 4

3

You should make a folder named images under your war/project_folder and place the images there.

And while setting the Url you shoud do

image.setUrl(GWT.getModuleBaseURL()+"images/im1.jpg");

You can use either GWT.getModuleBaseURL() or GWT.getHostPageBaseURL().

2
1

Create a public folder (named "public") alongside with folders "client" and "server". The content of the public folder will be copied into the war.

>src
  >com
    >test
    >client
--->public
        >images
    >server
    >shared

Voilà!

0

It is always better to use absolut URL rather than relative URL by using GWT.getModuleBaseURL(). If you want to use relative path, then your image should be in the war as described by your relative path.

In your case it is

war->images->img1.jpg
0

You need to put the images in the web app directory.

You can check your web app directory here Proeect --> Properties --> Google --> web Application

Here you will find the WAR directory

So in this directory , you need to put your images.

You can put the image directly or else you can make folders as you want

sample -

image path -->   WebContent/img/pics/recent/data/1/1.jpg 

String imagePath = "/img/pics/recent/data/1/1.jpg" ;

Image img = new Image(imagePath);

NOTE :- How ever GWT Image does not understand absolute file path , you need to use relative file path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.