How to get the path to an open workspace file for plugin development in eclipse

This is a question about developing plugins for the Eclipse platform:

I need to implement persistence without hardcoding the name of the data store used. I want to have multiple eclipse instances with my plugin working simultaneously with independent data stores.

One way to do this is to use the path to the workspace file to generate / search the name of the data store related to this particular workspace.

I tried org.eclipse.core.resources.ResourcesPlugin.getWorkspace (), but this does not seem to have a way to get this string.

To avoid confusion, I know -data and -showlocation. I want to access the showlocation text at runtime in an eclipse plugin.

I am using eclipse 3.5.2 for my current project.

Thanks in advance!

+3
source share
3 answers

This is from a news list that was several years ago , but you can try:

Platform.getLocation();
+5
source
Platform.getLocation();

NOT - workspace path (tried with eclipse 4.3 Kepler) as

@Inject @Named(E4Workbench.INSTANCE_LOCATION) private Location instanceLocation;

it will indicate the location of the configuration folder, but not the location of the workspace. One thing I discovered worked:

URL fileURL = FileLocator.find(Platform.getProduct().getDefiningBundle(),new Path(String_file2Locate), null);

(this only works for products not for plugins, but "String_file2Locate" is the path to the file of the file you want to use from the root / of your workspace folder)

Or also this . (but you will need a bite with the name of your plugin)

+2

Eclipse 3.X ResourcesPlugin.getWorkspace().getRoot().getLocation(); org.eclipse.core.resources.

+2

Source: https://habr.com/ru/post/1770282/


All Articles