简体   繁体   English

更新我的eclipse插件的资源文件

[英]Update resource file of my eclipse plugin

My plugin uses a resource file inside it's jar. 我的插件在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. 到目前为止,我已经获得了资源文件的URL ,但是由于它在jar中,所以我无法使用File来访问它。
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 . 但这给我一个UnknownServiceException指出该协议不支持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. 我希望有人对如何更新我的资源文件的内容有所了解。

You can't write to the plug-in jar. 您无法写入插件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. 这是工作空间.metadata/.plugins目录中为您的插件保留的目录。

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. 由您的插件来管理内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM