Where to cache a file for a Eclipse RCP-plugin

304 views Asked by At

I'm developing a plugin for an Eclipse-RCP-Application. Now I would like to cache a file (as I don't wan't to access the internet, whenever it's needed). This file should be accessible even after relaunching the application. Where would be the best place for it?

I thought about the workspace/.metadata folder. But I'm not sure if that is the right place and how to retrieve the location information. This should work, but I did not yet manage to find ResourcesPlugin

ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();

Can anybody give me a hint for the best place to store such a file?

1

There are 1 answers

1
greg-449 On BEST ANSWER

If you don't want users to see the file use the plug-in 'state location'. You get this using:

Bundle bundle = ... your plugin's Bundle

IPath path = Platform.getStateLocation(bundle);

The plugin's state location is a folder which is part of the workspace meta data (.metadata/.plugins/plugin id to be exact).

You can put whatever you like in this folder. It is up to your plugin to manage this data.

You can get the Bundle in various ways, such as:

Bundle bundle = FrameworkUtil.getBundle(getClass());

or

Bundle bundle = Platform.getBundle("plugin id");

Note: The code you mention in your question would put the file in the workspace and it would be visible to the user. ResourcesPlugin is in the org.eclipse.core.resources plugin.