need help with proper way to load image into app

Newbie alert! :slight_smile:

I have a logo that I want to display in a View. The code that creates the image is:

String IMAGE_DIR = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + “/WEB-INF/images/”;
Image image = new Image(“”, new FileResource(new File(IMAGE_DIR + “BlackStratus.png”)));

When I deploy the app war file to my IDE’s tomcat and access it via the browser the image displays fine. But when I deploy to our testing tomcat server, the images don’t show up. The web server’s error log gives the reason - an exception: / (No such file or directory)” is the host name of the server. I was expecting the actual complete path to the exploded war - i.e. something like ‘/home/nfadmin/webapps/reporting/WEB-INF/images/BlackStratus.png’

I am obviously confused and using the wrong Vaadin call as I’m not getting the path I thought I was getting from the VaadinService method calls :frowning: Can someone unconfuse me? The war file has the image under the WEB_INF/images/ directory.

Thanks for the help.

Hi Thomas,

here is my way to add a logo

import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Image;
addComponent(new Image(null, new ThemeResource("img/logos/logo35.png")));

img: directory inside your theme (webapp/VAADIN/themes/dashboard/img/logos/logo35.png)
logos: directory inside /img

I tried other ways to do that by example to load an html page. It seems that it s quick to put all your resources inside the theme and call the function ThemeResource().

Here another good link :!/thread/374589

Hi Philippe, I will try that - I actually already had a webapp/VAADIN/themes/blackstratus/images/ directory in which I kept image files that were referenced directly from the styles.css file.

This brings me to another warning I see in my web server’s error log:

INFO: Requested resource
[/VAADIN/themes/blackstratus/favicon.ico] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.

The funny thing is, I don’t reference “favicon.ico” anywhere in my app (at least Netbeans’ “Find” could not find it in any file in my project). Any idea what that might be about?

Thanks again,

Hi Thomas,

I have not yet deployed my application but did you deploy the content of webapp to your production server?

Hi again,
Not sure what you’re asking - all the warnings/messages I’ve talked about were observed when I deployed on our test server - which is like a production server. Everything works fine on my development machine, deploying to an IDE-managed tomcat instance.

See the content of your Tomcat directory. Goto to the webapps. You should see the directory of your application and inside the webapp directory of your vaadin application.

Modern Browsers try to reference an icon called favicon.ico for any page it opens (in the root of the page’s url). So it is not your application, but the browsers will try to access it.
The message is simply a way of telling you where you could place this icon…