Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Getting File path of the Bundle's location
Getting File path of the Bundle's location [message #330029] Sun, 13 July 2008 18:48 Go to next message
Eclipse UserFriend
Originally posted by: micha.bgl.gmx.de

Hi there,

I would like to have the concrete file path to the folder where all plugins
are stored in. I've tried bundle.getLocation(). But this gives me just the
name of the jar-file or the directory of my plugin. I would like to recieve
somthing like this : c:\programs\myApp\plugins\myplugin.jar
I hope you can help me with this.

regards,
micha
Re: Getting File path of the Bundle's location [message #330031 is a reply to message #330029] Sun, 13 July 2008 19:01 Go to previous messageGo to next message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
"Michael Weber" <micha.bgl@gmx.de> wrote in message
news:g5dim0$kgs$1@build.eclipse.org...
> Hi there,
>
> I would like to have the concrete file path to the folder where all
> plugins are stored in. I've tried bundle.getLocation(). But this gives me
> just the name of the jar-file or the directory of my plugin. I would like
> to recieve somthing like this : c:\programs\myApp\plugins\myplugin.jar

Plugins are not necessarily all in the same file path; they may be (indeed,
in 3.4, often are) distributed across multiple paths. Files within a bundle
are not necessarily accessible on the disk at all; they may be contained
within a jar file. The directory that any given plugin is located in may
not be writeable and is usually anyway not the right place to put
user-created files or config info.

Can you give some more info on what it is you're actually trying to do? We
can probably help steer you to a better solution.
Re: Getting File path of the Bundle's location [message #330035 is a reply to message #330031] Sun, 13 July 2008 19:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: micha.bgl.gmx.de

"Walter Harley" <eclipse@cafewalter.com> schrieb im Newsbeitrag
news:g5djcn$n5p$1@build.eclipse.org...
> "Michael Weber" <micha.bgl@gmx.de> wrote in message
> news:g5dim0$kgs$1@build.eclipse.org...
>> Hi there,
>>
>> I would like to have the concrete file path to the folder where all
>> plugins are stored in. I've tried bundle.getLocation(). But this gives me
>> just the name of the jar-file or the directory of my plugin. I would like
>> to recieve somthing like this : c:\programs\myApp\plugins\myplugin.jar
>
> Plugins are not necessarily all in the same file path; they may be
> (indeed, in 3.4, often are) distributed across multiple paths. Files
> within a bundle are not necessarily accessible on the disk at all; they
> may be contained within a jar file. The directory that any given plugin
> is located in may not be writeable and is usually anyway not the right
> place to put user-created files or config info.
>
> Can you give some more info on what it is you're actually trying to do?
> We can probably help steer you to a better solution.
>
I have a feature which consists of 2 separate plugins (libary-plugin and
program-plugin). One plugin is just a container for all my libaries, which I
use in the program-plugin. Finally the libary-plugin should also include an
executable windows application (the application will run only on computers
with windows). I would like to call the executable application in the libary
plugin from my program-plugin with Runetime.getRuntime().exec(command). For
this I need the complete filepath to the plugin's directory. If you have a
better proposal I would be pleased to know about it.

kind regards,
micha
Re: Getting File path of the Bundle's location [message #330101 is a reply to message #330035] Tue, 15 July 2008 03:50 Go to previous message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
"Michael Weber" <micha.bgl@gmx.de> wrote in message
news:g5dltp$4dv$1@build.eclipse.org...
> I have a feature which consists of 2 separate plugins (libary-plugin and
> program-plugin). One plugin is just a container for all my libaries, which
> I use in the program-plugin. Finally the libary-plugin should also include
> an executable windows application (the application will run only on
> computers with windows). I would like to call the executable application
> in the libary plugin from my program-plugin with
> Runetime.getRuntime().exec(command). For this I need the complete filepath
> to the plugin's directory. If you have a better proposal I would be
> pleased to know about it.

Indeed I do.

Rather than assuming that your bundle is in unpacked form and has directly
accessible files, it is better in this case to let the Eclipse framework
take care of that for you, using
org.eclipse.core.runtime.FileLocator.toFileURL(). This method will ensure
that a file is unpacked into a cache directory if it needs to be.

The code that I would recommend is something like the following:

Path path = // the bundle-relative pathname of your executable
URL installURL = plugin.getBundle().getEntry( path.toString() );
URL localURL = FileLocator.toFileURL( installURL );
Runtime.getRuntime().exec( localURL.toString() );

I've omitted all the necessary error checking and catch blocks, but that
should be trivial. The two methods of interest here are Bundle.getEntry(),
which gets an URL to your file, and FileLocator.toFileURL(), which unpacks
it from the bundle and saves it to a local directory if necessary.
Previous Topic:Mystery blank menu between File and Edit
Next Topic:creating dynamic visibleWhen expression
Goto Forum:
  


Current Time: Sun Jun 30 09:46:21 GMT 2024

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

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

Back to the top