简体   繁体   English

this.getClass()。getClassLoader()。getResourceAsStream()在RCP产品中不起作用

[英]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. 当我尝试从Eclipse运行RCP应用程序时, this.getClass().getClassLoader().getResourceAsStream(IMAGE_URL)可以正常工作。 But, when I am running it as a product, it is not running. 但是,当我将其作为产品运行时,它没有运行。

this.getClass().getClassLoader().getResourceAsStream() returns `null´. this.getClass().getClassLoader().getResourceAsStream()返回“ null”。 Any clue how to solve this? 任何线索如何解决这个问题?

Note: I have tried to solve this using Activator.getDefault().getBundle() . 注意:我尝试使用Activator.getDefault().getBundle()解决此问题。 But this as well is not working. 但这也不起作用。 It seems that Activator.getDefault() = null which means that plugin is not actiavted. 看来Activator.getDefault() = null意味着没有激活插件。 I also tried to put a break point there. 我还试图在此处设置一个断点。 Indeed the plugin variable in null in Activator. 实际上,Activator中的插件变量为null

What should I do? 我该怎么办?

Use FileLocator : 使用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. FileLocator其他方法将为您提供URL而不是流。

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. 检查MANIFEST.MF > Build如下图所示,并确保已选择资源以包含在二进制构建中。

在此处输入图片说明

For example, if you use the resource from icons folder it's will work perfectly when you run application from eclipse. 例如,如果您使用icons文件夹中的资源,那么当您从eclipse运行应用程序时,它将可以完美地工作。 After export product, this resource is not available. 导出产品后,此资源不可用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 this.getClass()。getClassLoader()。getResourceAsStream始终返回null - this.getClass().getClassLoader().getResourceAsStream always returning null this.getClass()。getClassLoader()和ClassLoader - this.getClass().getClassLoader() and ClassLoader this.getClass()。getClassLoader()。getResource()==异常 - this.getClass().getClassLoader().getResource() == Exception getClass()。getClassLoader()。getResourceAsStream()正在缓存资源 - getClass().getClassLoader().getResourceAsStream() is caching the resource getClass()。getClassLoader()。getResourceAsStream引发NullPointerException - getClass().getClassLoader().getResourceAsStream is throwing a NullPointerException java jar getClass().getClassLoader().getResourceAsStream 返回空指针异常 - java jar getClass().getClassLoader().getResourceAsStream return nullpointerexception Java OutputStream 等价于 getClass().getClassLoader().getResourceAsStream() - Java OutputStream equivalent to getClass().getClassLoader().getResourceAsStream() 等价于Jar中的this.getClass()。getClassLoader()。getResource(“。”)。toURI() - Equivalent of this.getClass().getClassLoader().getResource(“.”).toURI() from within a Jar getClass().getClassLoader().getResourceAsStream() 总是返回 null,资源在 application.jar 中 - getClass().getClassLoader().getResourceAsStream() always returns null, resource is in application.jar 如何将getClass.getClassLoader()。getResourceAsStream()值传递给FileOutputStream - How to pass getClass.getClassLoader().getResourceAsStream() value to FileOutputStream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM