Resource Manager getResource problem [message #71032] |
Tue, 22 January 2008 11:19  |
Eclipse User |
|
|
|
Hi
I am trying to get a resource froim the application packages. I use
this :
RWT.getResourceManager().getResource("ro/val/resource.txt")
this returns null
if I try to register the resource with
RWT.getResourceManager().register("ro/val/resource.txt")
I get exception :
Caused by: java.io.IOException: Resource to read not found:
ro/val/resource.txt
at
org.eclipse.rwt.internal.resources.ResourceUtil.openStream(R esourceUtil.java:228)
at
org.eclipse.rwt.internal.resources.ResourceUtil.readBinary(R esourceUtil.java:177)
at
org.eclipse.rwt.internal.resources.ResourceUtil.read(Resourc eUtil.java:46)
the resource.txt file is in the source path in the ro.val package
Thanks for any help,
Val
|
|
|
|
|
|
|
Re: Resource Manager getResource problem [message #72558 is a reply to message #71839] |
Fri, 01 February 2008 05:05  |
Eclipse User |
|
|
|
Originally posted by: rherrmann.innoopract.com
Val,
you need to set the ResourceManagers' context-classloader just before
you register the resource and reset it to its previous value afterwards.
If there is a class that resides in the same package as the resource to
load, its classloader would be a good candidate. Usually, any class that
resides in the same bundle should do (special cases left aside, they all
share the same classloader).
Typical code could look like this:
IResourceManager manager = ResourceManager.getInstance();
ClassLoader buffer = manager.getContextLoader();
manager.setContextLoader( <YourClass>.class.getClassLoader() );
try {
// register resource
} finally {
manager.setContextLoader( buffer );
}
HTH
Rüdiger
Val wrote:
> Unfortunately I still have some problems,
> I do not know which ContextClassLoader to set on the ResourceManager
>
> I have tried with calling
>
> RWT.getResourceManager().setContextLoader(Thread.currentThre ad().getContextClassLoader());
>
>
> in the start method of the plugin activator
>
> I still get the error : failed to register, Caused by:
> java.io.IOException: Resource to read not found: ro/val/resource.txt
>
> Thanks
>
> Rüdiger Herrmann wrote:
>> Val,
>>
>> you need to specify the class-loader that has access to the resources
>> in your plug-in (see
>> org.eclipse.rwt.resources.IResourceManager#setContextLoader) .
>>
>> Cheers,
>> Rüdiger
>>
>> Val wrote:
>>> Another thing, if I use
>>> this.getClass().getResource("/ro/val/resource.txt") it works
>>>
>>> Val wrote:
>>>> Hi
>>>>
>>>> I am trying to get a resource froim the application packages. I
>>>> use this :
>>>>
>>>> RWT.getResourceManager().getResource("ro/val/resource.txt")
>>>>
>>>> this returns null
>>>>
>>>> if I try to register the resource with
>>>>
>>>> RWT.getResourceManager().register("ro/val/resource.txt")
>>>>
>>>> I get exception :
>>>>
>>>> Caused by: java.io.IOException: Resource to read not found:
>>>> ro/val/resource.txt
>>>> at
>>>> org.eclipse.rwt.internal.resources.ResourceUtil.openStream(R esourceUtil.java:228)
>>>>
>>>> at
>>>> org.eclipse.rwt.internal.resources.ResourceUtil.readBinary(R esourceUtil.java:177)
>>>>
>>>> at
>>>> org.eclipse.rwt.internal.resources.ResourceUtil.read(Resourc eUtil.java:46)
>>>>
>>>>
>>>>
>>>> the resource.txt file is in the source path in the ro.val package
>>>>
>>>> Thanks for any help,
>>>> Val
|
|
|
Powered by
FUDForum. Page generated in 0.04233 seconds