44
votes

On Windows, the Java preferences, which you access in your application from java.util.prefs.Preferences are stored in the registry. Where are those stored on Mac OS X?

3
I have not found this to be true in Windows 7.javamonkey79
@javamonkey79, are you saying that your application Java preferences (accessed through java.util.prefs.Preferences) are not stored in the Windows registry on Windows? In my experience, and based on what I can read online, they are. For instance, see: java.sun.com/developer/technicalArticles/releases/preferencesavernet
Look at the date of the article - it is from 2001...long before Windows 7 :) I have found that they are no longer in the same place.javamonkey79
So you are saying that on Windows 7 the JVM isn't storing preferences in the registry anymore? This is not the subject of this question, but could you share with us more details on where it is stored?avernet
On my Windows 7, both user and system preferences are saved in the registry. At /HKEY_CURRENT_USER/Software/JavaSoft/Prefs/, HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Prefs/ and some at HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/JavaSoft/Prefs/ for 64bits.Alex

3 Answers

51
votes

From Apple Developer Connection:

The preferences files generated by the Preferences API are named com.apple.java.util.prefs. The user’s preferences file is stored in their home directory (~/Library/Preferences/). The system preferences are stored in /Library/Preferences/ and are only persisted to disk if the user is an administrator.

19
votes

Also, note that if the preference is nested enough, it won't directly be in com.apple.java.util.prefs, but rather in its own file. For instance, if you have a node /a/b/c, the key/value pairs for that node will be stored in a.b.c.plist.

The file will be either in ~/Library/Preferences/ or /Library/Preferences/, as for the com.apple.java.util.prefs file.

0
votes

When I create preferences objects using code:

package pl.marcinchwedczuk.iunrar.gui;

public class AppPreferences {
    private final Preferences preferences = Preferences
            .userNodeForPackage(AppPreferences.class);

Then the settings will be stored in:

/Users/$USER/Library/Preferences/pl.marcinchwedczuk.iunrar.plist

(for some reason gui part is missing, tested on macOS BigSur).

Also remember to call .flush() on preferences objects.