views:

589

answers:

2

I seem to be having trouble storing Java preferences using a Jython script. If in Jython 2.5 beta I use:

clazz = Class.forName('mypackage.myclass')
prefs = Preferences.userNodeForPackage(clazz);
# or Preferences.userRoot()
prefs.put('propertyname', 'yes')

The preferences are not stored. If I then add:

prefs.flush()

I get

java.util.prefs.BackingStoreException: Couldn't get file lock.

I am currently running this on Linux and Unix using Java 1.6. I'm hoping that I'm missing something obvious, since my Java applications can successfully use java.util.prefs.Preferences on the same system.

Any help would be greatly appreciated.

+1  A: 

This seemed relevant.

Could it simply be that a file is not created or the owner on the file has insufficient permissions? Or something like that?

John Weldon
Yes the user doesn't have permissions to write /etc/.java/.systemPrefsI'm curious if there is some preferences that writes to somewhere normally writable such as the user's home directory.
Eric Wendelin
+1  A: 

In the comments on your question and the answer you state that it tries to write /etc/.java/.systemPrefs. I don't think that's actually right.

clazz = Class.forName('mypackage.myclass')
prefs = Preferences.userNodeForPackage(clazz);
# or Preferences.userRoot()
prefs.put('propertyname', 'yes')

You are using Preferences.userNodeForPackage, so you will get the .userPrefs. These are located at /home/[user]/.java and should be writable.

With the systemPrefs you can get permission problems on linux. The preferences are stored in /etc/.java/.systemPrefs by default. If this directory isn't available(if you just copied the jre onto your system for example), the FileSystemPreferences class used to write the preferences falls back to [java.home]/.systemPrefs.

To call prefs.flush() shouldn't be necessary, since the preferences are saved in a predefined interval and when your program terminates.

abp