Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » resource loading
resource loading [message #314211] Wed, 04 April 2007 22:22 Go to next message
Aleksandr Kravets is currently offline Aleksandr KravetsFriend
Messages: 30
Registered: July 2009
Member
Hello,

I have a file in my plugin that I am trying to read. I am using
getClass().getResource() to load the file but always get
NullPointerException. What's the input string to getResource() should be
to correctly identify the file? I am trying to pass the whole package
path to the file, but nothing works.

thanks,
Alex
Re: resource loading [message #314231 is a reply to message #314211] Thu, 05 April 2007 12:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Alex,

Most often you'd use a path that doesn't start with "/" to look up the
resource in the same folder as the .class file itself.


Aleksandr Krvavets wrote:
> Hello,
>
> I have a file in my plugin that I am trying to read. I am using
> getClass().getResource() to load the file but always get
> NullPointerException. What's the input string to getResource() should
> be to correctly identify the file? I am trying to pass the whole
> package path to the file, but nothing works.
>
> thanks,
> Alex
>
Re: resource loading [message #314245 is a reply to message #314231] Thu, 05 April 2007 14:32 Go to previous messageGo to next message
Aleksandr Kravets is currently offline Aleksandr KravetsFriend
Messages: 30
Registered: July 2009
Member
Thanks Ed,

Right, the file that is in the same package as executing class I can
get, but I meant file in the plugin's root directory:

com.ak.myplugin:
src
xslt
file.xslt

I want to read file.xslt from class in src directory.

Also, when I create file from with the executing class' directory:

URL url = this.getClass().getResource("file.xslt");
File file = new File(url.toString());

I get file with path:

bundleresource:\1187\com\ak\wizard\file.xslt

Then, when I try to read this file using BufferedReader, the file cannot
be found.

thanks,
Alex

Ed Merks wrote:
> Alex,
>
> Most often you'd use a path that doesn't start with "/" to look up the
> resource in the same folder as the .class file itself.
>
>
> Aleksandr Krvavets wrote:
>> Hello,
>>
>> I have a file in my plugin that I am trying to read. I am using
>> getClass().getResource() to load the file but always get
>> NullPointerException. What's the input string to getResource() should
>> be to correctly identify the file? I am trying to pass the whole
>> package path to the file, but nothing works.
>>
>> thanks,
>> Alex
>>
Re: resource loading [message #314254 is a reply to message #314245] Thu, 05 April 2007 15:42 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Alex,

I think you'd use this.getClass().getResource("/file.xslt") but you
can't assume that the URL that comes back is a file: URL. It could be a
jar, or as you see, an OSGi-specific scheme. Can't you use
URL.openStream directly? You could also use a URL of the form
platform:/plugin/<plugin-ID>/file.xslt directly and open the stream for
that.


Aleksandr Krvavets wrote:
> Thanks Ed,
>
> Right, the file that is in the same package as executing class I can
> get, but I meant file in the plugin's root directory:
>
> com.ak.myplugin:
> src
> xslt
> file.xslt
>
> I want to read file.xslt from class in src directory.
>
> Also, when I create file from with the executing class' directory:
>
> URL url = this.getClass().getResource("file.xslt");
> File file = new File(url.toString());
>
> I get file with path:
>
> bundleresource:\1187\com\ak\wizard\file.xslt
>
> Then, when I try to read this file using BufferedReader, the file
> cannot be found.
>
> thanks,
> Alex
>
> Ed Merks wrote:
>> Alex,
>>
>> Most often you'd use a path that doesn't start with "/" to look up
>> the resource in the same folder as the .class file itself.
>>
>>
>> Aleksandr Krvavets wrote:
>>> Hello,
>>>
>>> I have a file in my plugin that I am trying to read. I am using
>>> getClass().getResource() to load the file but always get
>>> NullPointerException. What's the input string to getResource()
>>> should be to correctly identify the file? I am trying to pass the
>>> whole package path to the file, but nothing works.
>>>
>>> thanks,
>>> Alex
>>>
Previous Topic:Layout of Tables within Sections
Next Topic:Build Automatically
Goto Forum:
  


Current Time: Sat Nov 09 03:32:20 GMT 2024

Powered by FUDForum. Page generated in 0.03543 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top