If I use the Preference API to store user or system preferences, where are they stored on Windows and Unix?
2 Answers
For Windows systemRoot and userRoot are stored in HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs and HKEY_CURRENT_USER\Software\JavaSoft\Prefs respectively.
For Unix systemRoot and userRoot are stored in "/etc/.java" and "${user.home}/.java/.userPrefs", respectively.
Note that for Unix the locations can be changed by specifying "java.util.prefs.userRoot" and "java.util.prefs.systemRoot" properties
-
1On my UNIX box (which is Mac OS X), I get them in ~/Library/Preferences in multiple plist files. :>– HakanaiApr 24, 2014 at 1:08
-
Mac OS X uses the java.util.prefs.MacOSXPreferencesFactory class. See lists.apple.com/archives/java-dev/2010/Jul/msg00056.html for a discussion. Jun 11, 2014 at 8:09
-
@RichardNeish I don't see a
MacOSXPreferencesFactory
class in my Mac's JDK: i.imgur.com/wWDryFT.png– Ky.Jul 27, 2015 at 23:09 -
@BenC.R.Leggiero the
java.util.prefs.MacOSXPreferencesFactory
class should be inrt.jar
in JDK 1.7 or later. I don't have a Mac, so can't comment further. See hg.openjdk.java.net/macosx-port/macosx-port/jdk/file/… for the source code. Jul 28, 2015 at 8:07 -
@RichardNeish well, I'm compiling on JDK 8... and, here's all the items in
java.util.prefs
: i.imgur.com/GdpGIVf.png– Ky.Jul 28, 2015 at 12:33
I have to extend n002213fs' answer, because it seems to me, that the Storage Location is a big mess. Note that Windows saves it in the Windows Registry and Unix saves it in prefs.xml-files.
userRoot
- Windows (32Bit):
HKEY_CURRENT_USER\Software\JavaSoft\Prefs
- Windows (64Bit) with JVM (64Bit):
HKEY_CURRENT_USER\Software\JavaSoft\Prefs
- Windows (64Bit) with JVM (32Bit):
HKEY_CURRENT_USER\Software\Wow6432Node\JavaSoft\Prefs
- Unix:
System.getProperty("java.util.prefs.userRoot")
or (if the previous value is not set)~/.java/.userPrefs
systemRoot
- Windows (32Bit):
HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs
- Windows (64Bit) with JVM (64Bit):
HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs
- Windows (64Bit) with JVM (32Bit):
HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Prefs
- Unix:
System.getProperty("java.util.prefs.systemRoot")
or (if the previous value is not set)System.getProperty("java.home")+"/.systemPrefs"
(System.getProperty("java.home")
might be/etc/.java/
. You can check it in a terminal with$JAVA_HOME
.)
-
1For Unix, note that
FileSystemPreferences
always adds the.java/.userPrefs
root onto the configured path. Therefore the equivalent default property setting forjava.util.prefs.userRoot
is really just the home directory (or~
as you put it). Apr 30, 2018 at 14:52