简体   繁体   中英

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?

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.

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.

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM