Eclipse RCP: using the configuration directory

My Eclipse RCP application requires a configuration file containing some information for connecting to a remote database. Where is the best place to store this configuration file?

Can I use the default configuration directory (where "config.ini" is usually saved) for this purpose? If so, how can I get the File instance to this place programmatically? I also note that this directory does not exist in my Eclipse IDE.

Thanks.

+6
source share
5 answers

You have, as always, a number of options, depending on your requirements.

  • use Runtime Preferences to save to a PreferenceStore with a suitable PreferenceInitializer. Large enough and extensive API, in which a lot of thought. By default, preferences do not apply to the user or administrator, so you will need to do some work to open the preferences page or write to the properties file.

For less advanced / less work, especially if you don't have access to eclipse settings (e.g. OSGi on the server side):

  • set as a system property in RCP.ini. Unchanged by the user after starting, access to the RCP.ini file (eclipse.ini) is required, which may be possible, especially if you do not contribute to the IDE.
  • set as a system property, as an argument in a shortcut. Depends on the user using the shortcut. A custom shortcut must be created during installation.

If accessibility from the file system is really important, I would consider using one of the above methods to set the etc directory, and let your packages generate default property files in the etc directory if they are not on top for the first time. This essentially collapses your own preference store, so if you have a package of access settings, you might be better off doing this. This rather old User Settings FAQ may also be useful.

I really remember Erich Gamma (as in an interview with the Gang of Four and the JDT Technical lead) in which he says that there are about seven different preference mechanisms, and he never knew which one to use.

+5
source

As already stated, the Preferences API is something to look out for. There is also a secure settings API, which is suitable for storing user names and passwords encrypted on disk.

Another option is to use the OSGi service 'org.eclipse.osgi.service.datalocation.Location'. This provides access to various available places.

The third option is to define a system property in 'config.ini' that points to a file with your connection information using placeholders: ' my.connection.settings=@config.dir /mysettings.ini'. '@ config.dir' is a placeholder that is replaced with the actual path to the configuration directory.

+2
source

Take a look at the resource plugin - it can give you what you are looking for:

http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/resInt_filesystem.htm

+1
source

I usually like to hide configuration files in the bin directory or somewhere not in the root directory. You should probably save it in a subdirectory of your project so that you don't clutter up some random location on the system. If you need to get a file descriptor, you can simply do:

 File configFile = new File("./bin/remoteDbConfig.ini"); 

Then, if it is a true INI file, you can use Properties.load () to load and use the values ​​from the ini file.

You can also use the Preferences API to store the data needed for a remote connection.

0
source

To get the location of the file in the configuration directory, run:

new org.eclipse.core.runtime.preferences.ConfigurationScope (). getLocation (). toFile ();

0
source

All Articles