Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Unzip resources from jar bundle (e.g. in ...\configuration\org.eclipse.osgi\bundles\yyy)
Unzip resources from jar bundle (e.g. in ...\configuration\org.eclipse.osgi\bundles\yyy) [message #814670] Tue, 06 March 2012 18:50 Go to next message
Cristian Mising name is currently offline Cristian Mising nameFriend
Messages: 95
Registered: July 2009
Member
Hello,

I would like to unzip some resources from my plugin's jar bundle when Eclipse starts up.

I have seen that there is a directory (configuration\org.eclipse.osgi\bundles\yyy where yyy are digits) where some plugins unpack some of their resources. I am thinking of using this way.

So my first question: how can I retrieve the path (or URL) that points to the corresponding directory for my plugin (i.e. configuration\org.eclipse.osgi\bundles\yyy)? I think I could hardcode it based on the id of the plugin somehow, but I guess there is a "cleaner" approach to this.

The second question: is there another recommended way of doing this? E.g. to use a custom directory directly in the "configuration" directory? Or something in the "temp" directory of the current user?

Motivation for wanting to do this:
My bundles have some resources that need to exist directly on the HDD (i.e. not zipped within the JAR files, because they are needed by a module that only knows how to read files directly from the disk). Until now, I installed my bundles as directories, but I'd like to change that, and have my bundles packed as JARs.

Thank you in advance.
Best regards,
Cristian.
Re: Unzip resources from jar bundle (e.g. in ...\configuration\org.eclipse.osgi\bundles\yyy) [message #814712 is a reply to message #814670] Tue, 06 March 2012 19:57 Go to previous messageGo to next message
Cristian Mising name is currently offline Cristian Mising nameFriend
Messages: 95
Registered: July 2009
Member
I have found the answer to the first question. It looks something like this:

URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path("/dir/test.txt"), null);
URL fileUrl = FileLocator.toFileURL(url);


The second line of code unzips the file from the JAR into the configuration\org.eclipse.osgi\bundles\yyy\1\.cp directory (if the file is not already there).

Regarding my 2nd question? Is there another "best practice" way of achieving this besides the method above? This one seems pretty interesting.

Best regards,
Cristian.
Re: Unzip resources from jar bundle (e.g. in ...\configuration\org.eclipse.osgi\bundles\yyy) [message #814748 is a reply to message #814670] Tue, 06 March 2012 21:05 Go to previous messageGo to next message
BJ Hargrave is currently offline BJ HargraveFriend
Messages: 59
Registered: July 2009
Member
Use Bundle.getEntry to get access to the entries in your bundle and the write them out to your bundle's data file area (Bundle.getDataFile). You can then provide the file name to the library that insists on reading files.

The bundle data file area is preserved across bundles restarts and updates. So you only need to extract once and the future restarts can check to see if extraction is already done.
Re: Unzip resources from jar bundle (e.g. in ...\configuration\org.eclipse.osgi\bundles\yyy) [message #814779 is a reply to message #814748] Tue, 06 March 2012 22:08 Go to previous messageGo to next message
Cristian Mising name is currently offline Cristian Mising nameFriend
Messages: 95
Registered: July 2009
Member
Thanks for the reply.

I tried your suggestion, but in my case it doesn't seem to work. More exactly,
fileUrl = Activator.getDefault().getBundle().getEntry("/dir/test.txt");

returns the same url as
URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path("/dir/test.txt"), null);


This url gets the resource directly from the jar, without unpacking it.

Best regards,
Cristian.
Re: Unzip resources from jar bundle (e.g. in ...\configuration\org.eclipse.osgi\bundles\yyy) [message #814987 is a reply to message #814779] Wed, 07 March 2012 04:44 Go to previous message
BJ Hargrave is currently offline BJ HargraveFriend
Messages: 59
Registered: July 2009
Member
Yes. You need to unpack it. You need to read from the inputstream of the URL and write it to a file in your bundle data area. There is no magic unpacking here.
Previous Topic:Component Factories and multiple services
Next Topic:Problem in osgi launch configuration: doesn't keep start level
Goto Forum:
  


Current Time: Sun Oct 24 08:47:05 GMT 2021

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

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

Back to the top