I am developing an Eclipse plugin using Eclipse Plugin-in-project where it will add a menu item in the toolbar.
My plugin project is depending on one file which is located in the same plugin project I want the path of that file.
Below is the sample code I have used to get the path:
Bundle bundle = Platform.getBundle("com.feat.eclipse.plugin");
URL fileURL = bundle.getEntry("webspy/lib/file.txt");
File file = null;
String path=null;
try {
file = new File(FileLocator.resolve(fileURL).toURI());
path = file.getAbsolutePath();
} catch (URISyntaxException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
While running from Eclipse Run as > Eclipse Application it is giving me the correct path. But when I export my plugin as jar and add it in my Eclipse plugins folder its not giving me the correct path.
Please help me to resolve this!
As far as I know, Eclipse stores its plugins in its installation directory ( eclipse ). They might reside in eclipse/plugins or eclipse/dropins . You can copy the whole eclipse directory from your old box.
Use:
URL url = FileLocator.find(bundle, new Path("webspy/lib/file.txt"), null);
url = FileLocator.toFileURL(url);
File file = URIUtil.toFile(URIUtil.toURI(url));
When your files are packed in a jar FileLocator.toFileURL
will copy them to a temporary location so that you can access them using File
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With