Eclipse Preference store persistance

吃可爱长大的小学妹 提交于 2019-12-20 09:39:53

问题


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.

The options are from a preference store which saves the *.prefs files to "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)?


回答1:


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.

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 IPersistentPreferencesStore to access those tables via JDBC.




回答2:


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

  • 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 .prefs extension.
    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 .prefs extension.
  • for each project --for project-level settings -- in files stored in a .settings sub-directory of your project folder

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 .prefs files in the local workspace.metadata.plugins\org.eclipse.core.runtime.settings directory
  • 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 junctions for instance)



回答3:


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:

osgi.instance.area=@user.home/Application Data/earthrise
osgi.configuration.area=@user.home/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




回答4:


Just a thought!

Since the load() method of PreferenceStore does:

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

and you can either create a 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)...



来源:https://stackoverflow.com/questions/1539792/eclipse-preference-store-persistance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!