Getting File path of the Bundle's location [message #330029] |
Sun, 13 July 2008 14:48  |
Eclipse User |
|
|
|
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 #330101 is a reply to message #330035] |
Mon, 14 July 2008 23:50  |
Eclipse User |
|
|
|
"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.
|
|
|
Powered by
FUDForum. Page generated in 0.02983 seconds