Raven
Raven

Reputation: 3516

Update resource file of my eclipse plugin

My plugin uses a resource file inside it's jar.
However during runtime I want to update this resource therefore I'm looking for a way to write some content into this file.

So far I got the URL to my resource file, but as it is in a jar I can't use a File to access it.
Therefore I tried

URLConnection connection = resourceURL.openConnection();
connection.setDoOutput(true);
connection.connect();

OutputStream resourceOut = connection.getOutputStream();

But this thows me a UnknownServiceException stating that this protocol does not support an OutputStream.

I did some research on the web but I couldn't find an answer to my problem. I hope someone has an idea on how to update the content of my resource file.

Upvotes: 0

Views: 64

Answers (1)

greg-449
greg-449

Reputation: 111142

You can't write to the plug-in jar. On some platforms this will be installed in a read only location.

If you want to change data associated with a plug-in I suggest you put it in the plug-in 'state location'. This is a directory in the workspace .metadata/.plugins directory reserved for your plug-in.

Get the state location using:

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

IPath stateLoc = Platform.getStateLocation(bundle);

You can put anything you like in this directory. It is up to your plug-in to manage the contents.

Upvotes: 1

Related Questions