[英]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.