Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » development eclipse plugin - include image folder
development eclipse plugin - include image folder [message #303803] Tue, 23 May 2006 13:01 Go to next message
Eclipse UserFriend
Originally posted by: sparky.flo.com

hi there,

i have a very basic question about an eclipse plugin project.
in my project directory, i have an folder named "images" with all my icons
(e.g. for a tree). as long as i start the application as an normal java
applet, it works fine - i just load the graphic via:

new Image(Display.getCurrent(), "images/" + imagefilename);

but when i start my application as an eclipse plugin, it does not work
anymore - file not found io exception.
how can i configure my plugin in a way, so that it is possible to include
this folder and load these images?

i already included the image-folder in my "Binary Build" in the Build-Tab of
the Plugin-Configuration, but that did not work.

thanks in advance,
florian
Re: development eclipse plugin - include image folder [message #303808 is a reply to message #303803] Tue, 23 May 2006 13:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

The problem is that

new Image(Display.getCurrent(), "images/" + imagefilename);

says to look for the images directory in the current directory. The
current directory when running a plugin IS NOT the plugin's directory.
It is something else.

The best way to do images is to put the image directory in the root of
your java source folder and then use:

Image image = null;
InputStream in = getClass().getResourceAsStream("/images/"+imagefilename);
if (in != null) {
try {
image = new Image(Display.getCurrent(), in);
} catch (SWTException e) {
if (e.code != SWT.ERROR_INVALID_IMAGE) {
throw e;
// fall through otherwise
}
} finally {
try {
in.close();
} catch (IOException e) {
}
}
}

NOTE: Please take note of the leading '/' in "/images/". It is important
because otherwise the getResourceAsStream will put the package name as a
folder structure in front of the images folder and it won't find it.

This will then work whether run as an application or as a plugin.

Florian Schöllhammer wrote:
> hi there,
>
> i have a very basic question about an eclipse plugin project.
> in my project directory, i have an folder named "images" with all my icons
> (e.g. for a tree). as long as i start the application as an normal java
> applet, it works fine - i just load the graphic via:
>
> new Image(Display.getCurrent(), "images/" + imagefilename);
>
> but when i start my application as an eclipse plugin, it does not work
> anymore - file not found io exception.
> how can i configure my plugin in a way, so that it is possible to include
> this folder and load these images?
>
> i already included the image-folder in my "Binary Build" in the Build-Tab of
> the Plugin-Configuration, but that did not work.
>
> thanks in advance,
> florian
>
>

--
Thanks,
Rich Kulp
Re: development eclipse plugin - include image folder [message #303817 is a reply to message #303808] Tue, 23 May 2006 16:39 Go to previous message
Eclipse UserFriend
Originally posted by: sparky.flo.com

thanks a lot, it works now!


"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> schrieb im Newsbeitrag
news:e4vfrm$f10$1@utils.eclipse.org...
> The problem is that
>
> new Image(Display.getCurrent(), "images/" + imagefilename);
>
> says to look for the images directory in the current directory. The
> current directory when running a plugin IS NOT the plugin's directory. It
> is something else.
>
> The best way to do images is to put the image directory in the root of
> your java source folder and then use:
>
> Image image = null;
> InputStream in = getClass().getResourceAsStream("/images/"+imagefilename);
> if (in != null) {
> try {
> image = new Image(Display.getCurrent(), in);
> } catch (SWTException e) {
> if (e.code != SWT.ERROR_INVALID_IMAGE) {
> throw e;
> // fall through otherwise
> }
> } finally {
> try {
> in.close();
> } catch (IOException e) {
> }
> }
> }
>
> NOTE: Please take note of the leading '/' in "/images/". It is important
> because otherwise the getResourceAsStream will put the package name as a
> folder structure in front of the images folder and it won't find it.
>
> This will then work whether run as an application or as a plugin.
>
> Florian Sch
Previous Topic:Eclipse 3.2: Asynchronous TerminateAdapter Issues
Next Topic:nested jars inside bundle archives
Goto Forum:
  


Current Time: Mon Jun 09 15:32:58 EDT 2025

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

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

Back to the top