Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Deploy resources outside jars
Deploy resources outside jars [message #537041] Tue, 01 June 2010 07:05 Go to next message
Jan is currently offline JanFriend
Messages: 12
Registered: July 2009
Junior Member
Hello group,

I have a folder with ~200 images in my rcp application. I don't know the
names of them so I want to iterate over all files (images) in the folder
and create my SWT images.

Problem: The plugin is deployed as a JAR so I cannot get the content of
a directory. Even if I deploy it unpacked, the folder (representing the
jar) has a version number so I don't want to a hard reference.

Has someone a solution to this?
Thanks in advance



Btw, I'm using Eclipse 3.4.1.
Re: Deploy resources outside jars [message #537051 is a reply to message #537041] Tue, 01 June 2010 07:49 Go to previous messageGo to next message
HagenFriend
Messages: 90
Registered: April 2010
Member
On 06/01/2010 09:05 AM, Jan wrote:
> I have a folder with ~200 images in my rcp application. I don't know the
> names of them so I want to iterate over all files (images) in the folder
> and create my SWT images.

> Problem: The plugin is deployed as a JAR so I cannot get the content of
> a directory. Even if I deploy it unpacked, the folder (representing the
> jar) has a version number so I don't want to a hard reference.

You can access data inside a JAR (Java ARchive) programmatically during
runtime using Java.

E.g. to access to resources associated with a class, see:
http://java.sun.com/j2se/1.5.0/docs/api/
-> java.lang -> Class -> getResource / get ResourceAsStream

To access data inside an arbitrary JAR, see:
http://www.javaworld.com/javaworld/javatips/jw-javatip49.htm l
http://www.javaworld.com/javaworld/javatips/javatip49/JarRes ources.java

You can also access the helper classes:
http://java.sun.com/j2se/1.5.0/docs/api/
->java.util.jar


HTH-H
Re: Deploy resources outside jars [message #537147 is a reply to message #537041] Tue, 01 June 2010 13:04 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Jan wrote:
>
> Problem: The plugin is deployed as a JAR so I cannot get the content of
> a directory. Even if I deploy it unpacked, the folder (representing the
> jar) has a version number so I don't want to a hard reference.

You would get your Bundle and then you can use methods like
org.osgi.framework.Bundle.getEntryPaths(String) and
org.osgi.framework.Bundle.getEntry(String) (returns a URL which can be
used to get the InputStream). This avoids questions about what version
your plugin has or if it is a jar or directory.

Does that work for you?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Deploy resources outside jars [message #537178 is a reply to message #537147] Tue, 01 June 2010 14:45 Go to previous message
Jan is currently offline JanFriend
Messages: 12
Registered: July 2009
Junior Member
Thanks a lot Paul, getEntryPaths(String) is exactly the simple solution
I was looking for! I can iterate over the result and create my images
with Class.getResourceAsStream(path);

Jan


Am 01.06.2010 15:04, schrieb Paul Webster:
> You would get your Bundle and then you can use methods like
> org.osgi.framework.Bundle.getEntryPaths(String) and
> org.osgi.framework.Bundle.getEntry(String) (returns a URL which can be
> used to get the InputStream). This avoids questions about what version
> your plugin has or if it is a jar or directory.
>
> Does that work for you?
>
> PW
>
>
Previous Topic:How to log Platform/JFace/SWT - errormessages into my own logs?
Next Topic:Don't pack Plug-In when deploying
Goto Forum:
  


Current Time: Thu Apr 25 00:54:35 GMT 2024

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

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

Back to the top