Eclipse 首选项存储持久性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1539792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:03:41  来源:igfitidea点击:

Eclipse Preference store persistance

eclipseeclipse-rcp

提问by TJR

I have a multiple user/location RCP application that currently utilizes several user configurable options. Some preferences are for specific to the station, some are specific to the user.

我有一个多用户/位置 RCP 应用程序,目前使用多个用户可配置选项。一些偏好是特定于站的,一些偏好是特定于用户的。

The options are from a preference store which saves the *.prefs files to "workspace.metadata.plugins\org.eclipse.core.runtime.settings".

这些选项来自将 *.prefs 文件保存到“workspace.metadata.plugins\org.eclipse.core.runtime.settings”的首选项存储。

This would be fine if we were only using a single machine/user. But if a user were to go to another station, then the user would be using whatever preferences were setup for that station.

如果我们只使用一台机器/用户,这会很好。但是如果用户要去另一个站,那么用户将使用为该站设置的任何偏好。

Is it possible to specify another form for persistence (not files)?

是否可以指定另一种形式的持久性(不是文件)?

采纳答案by FelixM

It sounds like you need to store your preferences at a central location that all users/machines can reach. This means you have to implement your own IPersistentPreferencesStore. Then you can override org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore()to use it.

听起来您需要将您的首选项存储在所有用户/机器都可以访问的中心位置。这意味着您必须实现自己的IPersistentPreferencesStore. 然后您可以覆盖org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore()以使用它。

The bigger question is how to implement that central preferences store, but that depends on the technologies you are using. In general, if your project uses a central server, you probably should store your preferences there. For example, if your project already uses a relational database, one solution would be to create appropriate database tables and implement IPersistentPreferencesStoreto access those tables via JDBC.

更大的问题是如何实现中央偏好存储,但这取决于您使用的技术。一般来说,如果您的项目使用中央服务器,您可能应该在那里存储您的首选项。例如,如果您的项目已经使用关系数据库,一种解决方案是创建适当的数据库表并实现IPersistentPreferencesStore通过 JDBC 访问这些表。

回答by VonC

According the the eclipse wiki, the preferences are file-based, and stored:

根据eclipse wiki,首选项是基于文件的,并存储:

  • for each installation (but this may vary for multi-user installations), in files stored in <eclipse_home>/eclipse/configuration/.settings/.
    There is typically one file per plugin, with a .prefsextension.
    Note that very few plug-ins use installation-wide preferences.
  • for each workspace, in files stored in <workspace>/.metadata/.plugin/org.eclipse.core.runtime/.settings.
    There is typically one file per plugin, with a .prefsextension.
  • for each project --for project-level settings -- in files stored in a .settingssub-directory of your project folder
  • 对于每个安装(但对于多用户安装,这可能会有所不同),存储在<eclipse_home>/eclipse/configuration/.settings/.
    每个插件通常有一个文件,带有.prefs扩展名。
    请注意,很少有插件使用安装范围的首选项。
  • 对于每个工作区,在存储在<workspace>/.metadata/.plugin/org.eclipse.core.runtime/.settings.
    每个插件通常有一个文件,带有.prefs扩展名。
  • 对于每个项目 -- 对于项目级设置 -- 在.settings项目文件夹的子目录中存储的文件中

So if the file option is here to stay, you may need to:

因此,如果文件选项仍然存在,您可能需要:

  • either export/reimport the session settings manually in a user-specific directory (tedious)
  • or make some kind of automated mechanism:
    • to export the settings to the user's registry (HKEY_CURRENT_USER/Software/MyRCP/...) at the exit of the application, and
    • to import them by reading those registry keys and overriding the .prefsfiles in the local workspace.metadata.plugins\org.eclipse.core.runtime.settingsdirectory
  • or share those settings through some kind of user-specific link (a wrapper around the startup of the RCP would be in charge of making the right link, even on Windows with junctionsfor instance)
  • 在用户特定的目录中手动导出/重新导入会话设置(乏味)
  • 或制作某种自动化机制:
    • HKEY_CURRENT_USER/Software/MyRCP/...在应用程序退出时将设置导出到用户的注册表 ( ),以及
    • 通过读取这些注册表项并覆盖.prefs本地workspace.metadata.plugins\org.eclipse.core.runtime.settings目录中的文件来导入它们
  • 或通过某种特定于用户的链接共享这些设置(RCP 启动的包装器将负责建立正确的链接,例如,即使在带有连接的Windows

回答by Dale

You should read about multi-user installs

您应该阅读有关多用户安装的信息

In our case we have separated the per-user preferences from the application configuration by setting the config.ini to include the following:

在我们的例子中,我们通过将 config.ini 设置为包含以下内容,将每个用户的首选项与应用程序配置分开:

[email protected]/Application Data/earthrise
[email protected]/Local Settings/Application Data/earthrise/144/configuration
osgi.sharedConfiguration.area=c:/program files/earthrise/configuration
osgi.configuration.cascaded=true

The result of this is that any preferences set by the user are stored in their roaming profile, but application specific configuration data is stored in the Local Settings.

这样做的结果是,用户设置的任何首选项都存储在他们的漫游配置文件中,但特定于应用程序的配置数据存储在本地设置中。

This doesn't solve the problem of having user preferences specific to a particular workstation, but does allow to have each user to have their own preferences.

这并不能解决用户偏好特定于特定工作站的问题,但确实允许让每个用户拥有自己的偏好。

A catch with this is that the eclipse error log file will be stored in the instance area and get carried around in their roaming profile - not really what you want. You can code around this in the plug-in. See the workaround at eclipse bugzilla - search for 256502

一个问题是 eclipse 错误日志文件将存储在实例区域中,并在其漫游配置文件中随身携带 - 这不是您真正想要的。您可以在插件中对此进行编码。请参阅 eclipse bugzilla 中的解决方法 - 搜索 256502

回答by Erk

Just a thought!

只是一个想法!

Since the load() method of PreferenceStore does:

由于 PreferenceStore 的 load() 方法执行以下操作:

public void load() throws IOException {
    FileInputStream in = new FileInputStream(filename);
    load(in);
    in.close();
}

and you can either create a PreferenceStore

你可以创建一个 PreferenceStore

PreferenceStore(String filename)

or set its file name

或设置其文件名

public void setFilename(String name) {
    filename = name;
}

you might be able to "hack" the file name to some place on a shared server (or the users shared home folder perhaps)...

您可能能够将文件名“破解”到共享服务器上的某个位置(或者用户共享的主文件夹)......