Twitter Logo Follow us on Twitter
Project Information About this project

Static Resources

Every RAP application can host it's own static resources, like documents, scripts, images, or CSS-files. These can then be used for favicon, splash-screen, images in markup, within a browser widget, with the JavaScriptLoader or in any JavaScript-based custom widget. It is not necessary to register images used by CSS theming.

There are multiple ways to register a resource, with the main difference beeing the time and place the registration happens.

  • The ApplicationConfiguration is a good place to register resources that you know will be required throughout your applications lifecycle. Example:
    application.addResource( "foo/icon.png", new ResourceLoader() {
      public InputStream getResourceAsStream( String resourceName ) throws IOException {
        return this.getClass().getClassLoader().getResourceAsStream( "resources/icon.png" );
    } );
  • For workbench applications, the org.eclipse.rap.ui.resources extension point and IResource interface provide the same service as the application configuration above. One notable difference is that the extension also makes it simple for other bundles other than the RAP application itself to register resources. Also, any registered JavaScript file will automatically be executed when the web client is loaded. The JavaScriptLoader is not required in that case. Example for plugin.xml:
    <extension point="org.eclipse.rap.ui.resources">
      <resource class="my.project.resources.IconResource">
  • The most universal approach is using the ResourceManager directly, which allows registering and de-registering any resource at any time.
    ResourceManager resourceManager = RWT.getResourceManager();
    if( !resourceManager.isRegistered( "foo/icon.png" ) ) {
      InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream( "resources/icon.png" );
      try {
        resourceManager.register( resourceName, inputStream );
      } finally {

Important: To use the resource on the client (e.g. in a browser widget or the JavaScriptLoader), is it necessary to know it's public URL from the clients point of view. (The favicon in the application configuration/branding is an exception, here the path from the registration can be used). This information is in all cases provided by the ResourceManager:

String src = RWT.getResourceManager().getLocation( "foo/icon.png" );