Re: how to get a bundle's root file path? [message #85242] |
Mon, 26 March 2007 23:46 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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 #85417 is a reply to message #85318] |
Tue, 27 March 2007 15:44 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04167 seconds