Skip to main content



      Home
Home » Eclipse Projects » Equinox » Re: how to get a bundle's root file path?
Re: how to get a bundle's root file path? [message #85242] Mon, 26 March 2007 19:46 Go to next message
Eclipse UserFriend
Originally posted by: brett.ziptie.org

Ok, this only works on Equinox. This is no cross-OSGi implementation way to get the absolute path of a bundle. Having said that, here is the code for Equinox (apologies for the formatting, this forum eats my indentation, paste it into your editor and format it):

URL entry = context.getBundle().getEntry(".");
if (entry != null)
{
URLConnection connection = entry.openConnection();
if (connection instanceof BundleURLConnection)
{
URL fileURL = ((BundleURLConnection) connection).getFileURL();
URI uri = new URI(fileURL.toString());
String path = new File(uri).getAbsolutePath();
System.out.printf("This is the path: %s\n", path);
}
}

Note that BundleURLConnection is an internal Equinox class and you will get a warning marker in Eclipse as a result of using it.

Enjoy.

-Brett
Re: how to get a bundle's root file path? [message #85318 is a reply to message #85242] Tue, 27 March 2007 06:21 Go to previous messageGo to next message
Eclipse UserFriend
Many thanks, Brett! I tried your code but this first line gives me null

URL entry = context.getBundle().getEntry(".");

David
Re: how to get a bundle's root file path? [message #85417 is a reply to message #85318] Tue, 27 March 2007 11:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: brett.ziptie.org

> Many thanks, Brett! I tried your code but this first
> line gives me null
>
> URL entry = context.getBundle().getEntry(".");
>
> David

David, I'm not sure why that doesn't work for you, but you can use any file that resides in the root of your bundle.

-Brett
Re: how to get a bundle's root file path? [message #85476 is a reply to message #85417] Tue, 27 March 2007 12:22 Go to previous messageGo to next message
Eclipse UserFriend
Many thanks to Alex & Brett for help with this.

Brett, your method of getting absolute path work if I specify an actual file as in
URL entry = context.getBundle().getEntry("README.txt");

Alex has good points. I will endeavor to redo my app in the proper way.

Thanks!!
David
Re: how to get a bundle's root file path? [message #85873 is a reply to message #85318] Mon, 02 April 2007 18:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

> Many thanks, Brett! I tried your code but this first line gives me null
>
> URL entry = context.getBundle().getEntry(".");

How about this (unless you found a way without absolute paths ;-):

URL entry = context.getBundle().getEntry("/");
String path = FileLocator.toFileURL(entry).getPath();

FileLocator (from org.eclipse.equinox.common) isn't even internal.
Except: on windows we observed the above code to produce paths looking like:
/C:/Programme/Eclipse/plugins/my.plugin
a workaround for that is
String fixedPath = new File(path).getPath();
=:-0

--
Stephan Herrmann
Re: how to get a bundle's root file path? [message #85901 is a reply to message #85318] Tue, 03 April 2007 04:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: edwinb.panix.com

http://wiki.eclipse.org/index.php/FAQ_How_do_I_find_out_the_ install_location_of_a_plug-in%3F
Re: how to get a bundle's root file path? [message #118918 is a reply to message #85873] Fri, 03 October 2008 11:40 Go to previous message
Eclipse UserFriend
>FileLocator (from org.eclipse.equinox.common) isn't even internal.

On Equinox 3.4 it's org.eclipse.core.runtime.FileLocator

Thanks for the tip !

Still no generic OSGi way to find the bundle's root file path ?
Previous Topic:Error querying the registry... source?
Next Topic:Adaptor Hook Weirdness when launching from IDE
Goto Forum:
  


Current Time: Fri May 02 04:43:20 EDT 2025

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

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

Back to the top