Best way to package icons in add on jar? - FIXED


I noticed that the pagination add on asks user to copy out icon files when you deploy the pagination bar:

“For 6+ you must place “icons files” to folder : WebRoot/VAADIN/themes/paginationbar/icons/16/
“icons files” are in “WebRoot” folder of zip package.”

I have to do something similar, is this the only way to do it? I would like to include the icon files inside the jar but I’m not sure if thats allowed - I tried to access my icons as theme resources and classpath resources and it did NOT work - the files were in the jar, but didn’t come through in the front end.




Anyone? I really would like to publish an addon, but this is stopping me in my tracks right now…

Any help much appreciated!

The directory WebRoot is a something specific to certain development environments (Eclipse) and does not exist inside WARs or JARs but rather tells what should be included in a WAR. Other environments use different directories for this, e.g. /src/main/webapp in Maven.

In your JAR file, the icons should be under /VAADIN/themes/… to be accessible as theme resources, and you must map /VAADIN/* (in addition to the application path) to the Vaadin servlet in web.xml. Only files under /VAADIN/* are served by the servlet as static resources (with recent Vaadin versions).

Alternatively, in high load production systems, you could also configure your server to serve such static resources directly without even asking the servlet.

Hi Henri,

Ya, I understand that part, but what about when you want to create an add on which has icons that go along with it? I have created a vaadin project, and it runs fine and has a couple of icons and displays properly. However, when I select File/Export/Vaadin Add-on package, eclipse creates a jar for me which has the icons in it, but when the jar is deployed into another vaadin project the icons do not show up. The code runs and works properly but the icons don’t display!

So, the question is → How can I export my project as an add on and have the icons show up when deployed in another project?

I originally tried to refer to the icons as a ThemeResource, but I noticed that when the add on was deployed in another project, the path was incorrect because the theme was different in the new project.

ie. my resource expect to be at ‘/addonTheme/image.png’ (which was fine for my original project), but in the other project (where the jar was deployed to) it was being referred to as ‘/deployedProjectTheme/image.png’

This obviously won’t work, so then I started referring to the images as a ClassResource:

Resource addIconResource = new ClassResource("img/icons/add.png", getApplication()); 

but this doesn’t work either!

I didn’t think this would be so difficult!

Thanks for your help,



Turns out I stubbed my toe on a Vaadin bug:

ouch, that hurt, probably wasted 5+ hours on it, sigh.

So, if you are reading this, get vaadin 6.7.1 asap if your icons are not showing up!

But, this doesn’t seem to be the end of it. I’m using ClassPath to access the icons because ThemeResource’s don’t seem to be appropriate and don’t work when you have deployed the jar to another project with a different theme name. Is this correct, or some way around this?

As well as making sure the icons are in the classpath, I have to refer to them with a leading slash or else the path information gets stripped out due to:

* Gets the virtual filename for this resource.
* @return the file name associated to this resource.
* @see com.vaadin.terminal.ApplicationResource#getFilename()
public String getFilename() {
int index = 0;
int next = 0;
while ((next = resourceName.indexOf(‘/’, index)) > 0
&& next + 1 < resourceName.length()) {
index = next + 1;
return resourceName.substring(index);

This behavior seems like a bug to me, why would the ClassResource want to strip out path information if the resource don’t start with a slash? Is this a bug?



shameless bump

Henri, do you have a moment to clear this up for me please?

Thank you,


Have I stumped everyone making add-ons?

Hi Mark,

You pretty much bumped into one of the difficult issues with add-on theming. Vaadin 7 will definitely address this issue.

But for now, you could try the ThemeResource again, but use a relative path like “…/addonTheme/themeImage.png”, so it won’t depend on the actual theme used by the application. That should work.

Hi Jouni,

OMGoodness, thank you. Been waiting a long time for a bit of help on this.

That little trick needs to be somewhere easily found, wasted a lot of time on this.

It worked like a charm, I have icons again, yay!

I’m less interested now that it works, but I still don’t know why the ClassResource works the way it does - I don’t think it should strip out the leading /, and that should be corrected if its a bug.

Marking as answered though, because I have icons!

Thank you!