ClassResource in JAR is not accessible, why?

I have a problem. I have a library project with a class (MyButton) that extends Button. This uses an icon by means of a ClassResource:

setIcon(new ClassResource("icon.png"));

It works perfectly. However, if I create a JAR that contains this component and the icon and I add this dependency to my project, MyButton instances in my project do not show the icon in runtime.

Why? Is not ClassResource class able to know where is the icon though it is in the classpath? Is not there any solution?

No one reply? Don’t Vaadin allow manage Resource objects in a JAR sucessfully? … It seems unbelievable…

Old thread, but in case still use for somebody: ClassResource performs getAssociatedClass().getResourceAsStream(resourceName) where associated class is typically UI.getCurrent().getClass(). Thus, anything that the class loader of the class com.vaadin.ui.UI can load should work. Perhaps the location of the file in the JAR is not on the classpath with the resource path used, or in your deployment the UI class is loaded with a classloader that does not have access to the JAR.

It should also be possible to write a subclass of ClassResource which overrides getStream() to access resources in other ways.