Usage of ApplicationResource


I wrote a simple application, it should only display an image.
I my Application I uses the following code

label.setIcon( new ClassResource( "find.png", this ) );

My find.png is located in the the package as the Application class.
After running the application no Image will be displayed, in the logs I found
INFO: Requested resource [VAADIN/APP/1/find.png]
not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.

Whats wrong ?
After I added

    public String getRelativeLocation( final ApplicationResource resource) {

		try {
			Field field = Application.class.getDeclaredField("resourceKeyMap");
			Map<Application,String> map = (Map<Application, String>) field.get( this );
	    	String key = map.get(resource);
	    	if( key != null ) {
	    		return  "app://APP/" + 1 + "/x";
		} catch (Exception e) {
		return super.getRelativeLocation(resource);

I my Application everythings works as expected.

I’m not sure whats wrong, do I used the api wrong ?

Best regards,

ClassResource looks for data on the classpath using the Application’s classloader. This means that the path to the package where your image is located must be defined. If your Application class is in the com.example.myapp package and you your find.png in the same package, then you should use “com/example/myapp/find.png”.

EDIT — Ignore my previous comments, I was mixing up concepts.

Upon closer investigation, it seems that the issue is somehow related to how your application is deployed, though I can’t tell exactly what is going on there…