This is kind-of a strange question, so please bear with me.
We have a Java application that has a utility for Mathematica 12 that lets you run our app from Mathematica using JLink. This works fine on macOS and Windows. On Linux we get an exception, thrown from the
After much nosing around, I noticed the JVM from Mathematica on Linux was setting
-Djava.util.prefs.PreferencesFactory=com.wolfram.jlink.DisabledPreferencesFactory, and in the Mathematica SystemFiles I found that
DisabledPreferencesFactory class to be returning the null value causing our exception.
That’s when I found this code in
InstallJava.m (lines 518 to 527) in the JLink folder (in a
createCommandLine function used by
(* Disabling the Java prefs subsystem on Unix/Linux is a hack to work around a very annoying problem with that subsystem. Maybe Sun will fix this in JDK 1.5. Because this is an experimental fix, we'll put in the $ disablePrefs flag as a backdoor that could be set from top level before launching Java. *) prefsSpec = If[!osIsWindows && !osIsMacOSX && $ disablePrefs =!= False, " -Djava.util.prefs.PreferencesFactory=com.wolfram.jlink.DisabledPreferencesFactory", (* else *) "" ];
That made it clear where the issue is coming from, and it looks like we even have a way to disable this, as we’re on Java 1.8 and I don’t think the issue discussed is still a problem, so I’m fine setting that
$ disablePrefs flag to false.
So my question is, how do I set that
$ disablePrefs flag in a way that the JLink package will see it and not set this Java argument? I tried doing it inside a Mathematica 12 document before loading our package (
$ disablePrefs = False;), and then also modified our package to set that flag before calling
InstallJava from JLink, but neither worked. I’m hoping this is a simple Mathematica thing I just don’t know how to do, as I haven’t used it much. Thanks.