How do I get the file path of the open workspace for developing plugins in eclipse
This is a question specifically about plugi开发者_JAVA百科n development for the Eclipse platform:
I need to implement persistence without hardcoding the name of the datastore I am using. I want to be able to have multiple instances of eclipse with my plugin running at the same time with independent datastores.
One way of doing this would be to use the file path of the workspace to generate/find the name of the datastore relating to that particular workspace.
I have tried org.eclipse.core.resources.ResourcesPlugin.getWorkspace(), but this doesn't seem to have a way to get that string.
To avoid any confusion, I am aware of -data and -showlocation - I want to access the text of showlocation at runtime in an eclipse plugin.
I am using eclipse 3.5.2 for my current project.
Thanks in advance!
This is from a news list that's a few years old now, but you could try:
Platform.getLocation();
Platform.getLocation();
is NOT the path to the workspace (tryed with eclipse 4.3 Kepler) like
@Inject @Named(E4Workbench.INSTANCE_LOCATION) private Location instanceLocation;
it will give the location of the configuration folder, but not the workspace location. One Thing I found that worked was:
URL fileURL = FileLocator.find(Platform.getProduct().getDefiningBundle(),new Path(String_file2Locate), null);
(this only works for products not for plugins and "String_file2Locate" is the filepath of the File you want to use, from the root / of your workspace folder)
Or also like this. (but you will need a sting with the name of your plugin)
For Eclipse 3.X, use ResourcesPlugin.getWorkspace().getRoot().getLocation();
after importing org.eclipse.core.resources plugin.
精彩评论