| 
| Re: how to get a bundle's root file path? [message #85242] | Mon, 26 March 2007 19:46  |  | 
| Eclipse User  |  |  |  |  | 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
 |  |  |  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
Powered by 
FUDForum. Page generated in 0.10901 seconds