Since MATLAB requires Java for some of its features (e.g. for displaying the GUI or running Java programs within MATLAB), it ships with Sun’s Java Runtime Environment (JRE). Most people already have installed a JRE on their system that usually is newer than the one MATLAB comes with. Therefore, it seems to be a good idea to let MATLAB make use of the installed JRE instead of its own. This easily can be done by setting the environment variable MATLAB_JAVA. That’s the theory.
In practice, changing MATLAB’s JRE makes some trouble—at least when you are running Linux. Currently, I’m running MATLAB R2008b (aka 7.7) on Fedora 10 and notice some problems with MATLAB’s own JRE: First, printing does not work. Second, when starting MATLAB I get some strange error (locking assertion failure), which luckily does not seem to have any further consequences. Therefore, I decided to switch to OpenJDK, which comes with Fedora. Setting MATLAB_JAVA to /usr/lib/jvm/jre should do the job. Unfortunately, with this setting MATLAB fails to start, giving me the following error message:
Unable to initialize com.mathworks.mwswing.MJStartup
Fatal Error on startup: Failure loading desktop class
Although I spent some time in debugging this issue, I still have no clue what’s going wrong. My hope is that this issue will be resolved in the next release of MATLAB.
And indeed, MATLAB R2009a (aka 7.8) can be started using OpenJDK. However, MATLAB’s help browser displays only empty pages, which actually are not very helpful. When opening the help browser I get the following Java error:
Exception in thread "Loader for _view_0" java.lang.VerifyError: class org.mozilla.javascript.IdScriptable overrides final method getAttributes.(Ljava/lang/String;Lorg/mozilla/javascript/Scriptable;)I
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:637)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at ice.util.Defs.getClass(OEAB)
at ice.util.Defs.newClassInstance(OEAB)
at ice.storm.DefaultFactory.createScripter(DefaultFactory.java:91)
at ice.storm.StormBase.getScripter(StormBase.java:1590)
at ice.pilots.html4.ThePilot.doScriptEval(ThePilot.java:405)
at ice.pilots.html4.DOMBuilder.loadIfGivenExternalScript(DOMBuilder.java:1003)
at ice.pilots.html4.DOMBuilder.endElement(DOMBuilder.java:944)
at ice.dombase.LexBase.endElement(OEAB)
at ice.dombase.LexBase.char_buf(OEAB)
at ice.dombase.LexBase.arraycopy(OEAB)
at ice.dombase.LexBase.parse(OEAB)
at ice.dombase.LexBase.parse(OEAB)
at ice.pilots.html4.ThePilot.do_parse(ThePilot.java:816)
at ice.pilots.html4.ThePilot.parse(ThePilot.java:717)
at ice.storm.StormBase.do_render_content(StormBase.java:1090)
at ice.storm.Viewport.runAsynchronousLoad(Viewport.java:373)
at ice.storm.LoadThread.run(LoadThread.java:52)
Fortunately, I found out how to fix this problem. The reason for the error is that the developers of OpenJDK decided to place Rhino (an open implementation of JavaScript) into OpenJDK’s bootclasspath, which essentially overrides the (quite old) version of Rhino used by (and shipped with) MATLAB with an incompatible one. Most likely this is a bug in OpenJDK, similar to a bug already reported for OpenOffice.org.
So, what can be done to get rid of this problem? As a workaround (until the developers of OpenJDK finally fix this problem) I suggest to delete the symlink /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/rhino.jar, which currently points to /usr/share/java/rhino.jar.
Now, OpenJDK works fine with MATLAB and I’m even able to print. Apart from that, the fonts look better.
To summarize: MATLAB R2008b does not work with OpenJDK, but MATLAB R2009a does if you remove rhino.jar from OpenJDK.
UPDATE: The IcedTea/OpenJDK guys managed to move OpenJDK’s version of Rhino to a different namespace (as of IcedTea6 1.8), which should solve the problem described in this post.