java system preferences under different users in linux

niken picture niken · May 30, 2014 · Viewed 36.9k times · Source

I'm trying to run multiple jvms (including tomcat) under different users on one linux box. I'm not seeing too many issues, but in catalina.out I keep seeing this:

May 30, 2014 1:16:16 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7626 ms
May 30, 2014 1:16:37 PM java.util.prefs.FileSystemPreferences$2 run
WARNING: Could not create system preferences directory. System preferences are unusable.
May 30, 2014 1:16:55 PM java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode
WARNING: Could not lock System prefs. Unix error code -158097957.
May 30, 2014 1:16:55 PM java.util.prefs.FileSystemPreferences syncWorld
WARNING: Couldn't flush system prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.

I did some digging/reading and deduced the following:

An administrator with root access must create the system preferences directory /etc/.java/.systemPrefs with drwxr-xr-x access.

Java's looking for /etc/.java/.systemPrefs/.system.lock and /etc/.java/.systemPrefs/.systemRootModFile

Manually creating the above files (use "touch" to create empty files) and their containing directories should fix. Rights to the files should be 544, rights to their directories should be 755, owner and group are root for all.

But

I am not root, getting someone to run root is expensive and I have multiple users running jvms, does that mean i have to create those files and set up permissions just so that all users have access with those privileges?

Has anyone ever run into this issue and if they have is there a simpler solution i am missing?

Answer

niken picture niken · May 30, 2014

Set these settings per user:

mkdir -p ~/.java/.systemPrefs
mkdir ~/.java/.userPrefs
chmod -R 755 ~/.java
export JAVA_OPTS="-Djava.util.prefs.systemRoot=/home/user/.java -Djava.util.prefs.userRoot=/home/user/.java/.userPrefs"
  <run appl>

Without creating the directories, some Java virtual machines default to /etc/.

See also: Java - Setting Preferences backingstore directory