Srijani Ghosh
Srijani Ghosh

Reputation: 4216

this.getClass().getClassLoader().getResourceAsStream()is not working in RCP product

this.getClass().getClassLoader().getResourceAsStream(IMAGE_URL) is working perfectly when I am trying to run my RCP application from Eclipse. But, when I am running it as a product, it is not running.

this.getClass().getClassLoader().getResourceAsStream() returns `null´. Any clue how to solve this?

Note: I have tried to solve this using Activator.getDefault().getBundle(). But this as well is not working. It seems that Activator.getDefault() = null which means that plugin is not actiavted. I also tried to put a break point there. Indeed the plugin variable in null in Activator.

What should I do?

Upvotes: 1

Views: 495

Answers (2)

Aleksandr Korotkov
Aleksandr Korotkov

Reputation: 92

I had the same problem. The reason was the lack of resources in the product build. Check MANIFEST.MF > Build like on picture below and make sure that resources is selected to include in the binary build.

enter image description here

For example, if you use the resource from icons folder it's will work perfectly when you run application from eclipse. After export product, this resource is not available.

Upvotes: 1

greg-449
greg-449

Reputation: 111142

Use FileLocator:

Bundle bundle = FrameworkUtil.getBundle(getClass());

InputStream is = FileLocator.openStream(bundle, new Path("relative path"), false);

Other methods of FileLocator will give you a URL instead of a stream.

Upvotes: 2

Related Questions