Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to reference a file packaged in a plugin
How to reference a file packaged in a plugin [message #275715] Thu, 11 November 2004 11:06 Go to next message
Eclipse UserFriend
Originally posted by: eemorale.cs.ucsd.edu

Hi,

I have a configuration file (.txt) that I want to load by default in
an editor. I was wondering how to package the config file correctly
and correctly reference it if it's packaged in the deployment jar file
of a plugin.

I basically want to do something as simple as:

String loc = location of configuration file packaged in plugin
File f = new File(loc);

Thanks,
Ernesto
Re: How to reference a file packaged in a plugin [message #275717 is a reply to message #275715] Thu, 11 November 2004 11:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

The way is to use InputStreams and

this.getClass().getResourceAsStream("filename relative to the package of
the class doing getResourceAsStream")

or

this.getClass().getResourceAsStream("/filename relative to root of jar")

The difference between the two above is the leading slash ('/'). Without
the leading slash the file is relative to the package the class is
located in, with the slash, it is relative to the root of the jar instead.

File(loc) doesn't work on files within a jar. It only works on files in
the file system.

--
Thanks,
Rich Kulp
Re: How to reference a file packaged in a plugin [message #275723 is a reply to message #275717] Thu, 11 November 2004 12:19 Go to previous message
Eclipse UserFriend
Originally posted by: Chris_Laffra.ca.ibm.com

Rich shows the correct way to get to application resources.
To get resources from your plug-in, you will have to read

http://www.eclipsefaq.org/chris/faq/html/faq103.html

Chris

"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
news:cn031f$m7n$1@eclipse.org...
> The way is to use InputStreams and
>
> this.getClass().getResourceAsStream("filename relative to the package of
> the class doing getResourceAsStream")
>
> or
>
> this.getClass().getResourceAsStream("/filename relative to root of jar")
>
> The difference between the two above is the leading slash ('/'). Without
> the leading slash the file is relative to the package the class is
> located in, with the slash, it is relative to the root of the jar instead.
>
> File(loc) doesn't work on files within a jar. It only works on files in
> the file system.
>
> --
> Thanks,
> Rich Kulp
Previous Topic:cvs whitespace error
Next Topic:specify java home
Goto Forum:
  


Current Time: Sun Jul 27 01:47:28 EDT 2025

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

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

Back to the top