constantlearner
constantlearner

Reputation: 5247

Preferences getting locked

The reason is that the preferences-systems tries to write a lock file at a location where "normal" users have no write permissions on Linux workstations. (/opt/j2se/linux/ix86/j2se_1.5.0_12/jre/.systemPrefs/.system.lock)

1)I cant give write permission to the directory.

2)I am doing something like this:

private void loadSamplePreferences() throws IOException,
            BackingStoreException, InvalidPreferencesFormatException {
        ClassLoader contextClassLoader = Thread.currentThread()
                .getContextClassLoader();
        InputStream stream = contextClassLoader
                .getResourceAsStream("example.xml");

        Preferences pref = Preferences.systemRoot().node("example");

        pref.removeNode();


        Preferences.importPreferences(stream);
    }

I tried to setpreferences with dummy factory but still problem exists in loading

 System.setProperty("java.util.prefs.PreferencesFactory", "DisabledPreferencesFactory");
       System.setProperty("java.util.prefs.systemRoot", targetpath);
       System.setProperty("java.util.prefs.userRoot", targetpath);

How to solve this?

Upvotes: 2

Views: 1048

Answers (1)

Angel O'Sphere
Angel O'Sphere

Reputation: 2666

You likely want to use Preferences pref = Preferences.userRoot().node("example"); ... systemRoot is intended for system wide preferences for all users.

Upvotes: 1

Related Questions