07.24.06

Change Java Virtual Machine in MATLAB for Linux

Posted in Java, Matlab at 9:57 pm by keith

Matlab Logo

When you first purchased and installed your MATLAB several months (or a few years) ago, you will find that the Java Virtual Machine (JVM) that they supply are either out-dated or obsolete. Actually, I should be saying “obsolete” because in spite of that, MATLAB still functions well with old version of JVM. For instance, the Windows version of Matlab 6.5 will ship along with Sun’s Java Run-time Environment (JRE) version 1.4.2. Only does the latest version of Matlab (v7) comes with JRE version 1.5. Linux (UNIX) users are much luckier in the sense that if the version of your Java VM before Matlab installation is of the latest version, then there isn’t much for you to do. However, if you already have Matlab installed and running an old version of JVM, then chances are you will need to follow some ways to change your JVM. So why do users want to upgrade (or change) their Java VM in Matlab? For me, it is basically out for fun. As for others, it is purely compatibilty of similar version on Java VM platform.

Right, in this post, I will introduce how to change the JVM for Matlab in Linux system. Unfortunately, I will not discuss anything with relate to Windows version of Matlab, although there may be several other posts in Google which you can search to get some results.


Assume the root directory of Matlab, $MATLAB, is installed in /usr/local/matlab (though you could have installed it in other places). Now, the first thing to do is to check what your latest version of JRE is by typing in the console:

java -version

If your Java version is 1.5.x, then I do not think there is any need for you to upgrade your JVM, unless you still find adventurous to do so. If your version is 1.4.x, then you might want to consider using upgrading. (Note that, it is not a necessity to upgrade your JVM in Matlab, unless you really feel want to, or your work requires you to).

To proceed, first upgrade your JRE, by downloading the JRE binaries from Sun website. In fact, some of the Linux distribution already has packages for the latest Sun’s Java Run-time Environment version. Check it out from your depositories first before installing them manually yourself. Also, note that you do not need the Java Development Kit (JDK), only the JRE will do.

Once that has been installed in your Linux system, which is likely to be in the following directory: /usr/lib/jvm/java-1.5.0-xxxx, now it is time to change your JVM in Matlab.

The method I have chosen is a quick fix, and some of you may not find it is the best way to do so, but as long as it works, I think it’s fine.

  1. Access the following directory:

    cd /$MATLAB/sys/java/jre/glnx86

    where $MATLAB may be /usr/local/matlab, depending on where you have installed Matlab.

  2. You are likely to find a file and a folder (or a link). The file is jre.cfg and the folder is the current JVM that your Matlab uses.
  3. Change the name of that folder (or link), i.e. jre1.4.2 to something else, such as zzzjre.1.4.2.
  4. Create a symbolic link to the new JVM which you has just installed by:

    ln -s /usr/lib/local/jvm/java-1.5.0-xxxx/jre jre1.4.2

    This will re-create a link to the new Java VM using the old folder name. (Note, xxxx will be the remaining folder name of course).

  5. Once that’s done, run Matlab on a new console to test that out:

    matlab -nosplash -nodesktop

    Then, in the Matlab environment, type:

    ver java

    It should show you that Matlab is running the version of Java which you has installed. Congratulations!

Basically, I have tried this on two different operating systems, Suse 9.3 and Ubuntu 6.06. So, it should, more or less, work on other Linux distributions as well.

Troubleshooting

  1. If there is already a symbolic link present in $MATLAB/sys/java/jre/glnx86, then it would be wise to remove that link to any old java version first before creating a new symbolic link:

    cd $MATLAB/sys/java/jre/glnx86
    unlink jre1.4.2

So, that’s it! The fast and quick fix to change your Java Virtual Machine (JRE) version in Matlab for Linux (UNIX).

Don’t forget to Digg Me!!

2 Comments »

  1. How to change JVM in MATLAB for Linux - Stock Market Analysis at DeepMarket said,

    January 20, 2007 at 2:22 am

    […] I have intended - for many many years now - to try out MATLAB or Mathematica for doing some more advanced analysis of the stock market - and those intentions have remained just that.  Good intentions.  The sad fact is - I often end up just using Excel for quick and dirty work.  I did want to point out this article about how to change MATLAB’s JVM under Linux for several reasons: […]

  2. Pedro said,

    June 3, 2007 at 12:08 am

    I’ve tried these procedure described above with version 1.6.0.01. At the begining it works good, but after reboot the computer, matlab do not longer starts. I got the following message :

    java.lang.UnsatisfiedLinkError: Can’t load library: /usr/lib/jvm/jre1.6.0_01/lib/amd64/motif12/libmawt.so
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at sun.security.action.LoadLibraryAction.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.awt.NativeLibLoader.loadLibraries(Unknown Source)
    at sun.awt.DebugHelper.(Unknown Source)
    at java.awt.Component.(Unknown Source)
    at javax.swing.ImageIcon.(Unknown Source)
    at com.mathworks.mwswing.desk.Desktop.(Desktop.java:104)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.mathworks.jmi.OpaqueJavaInterface.findClass(OpaqueJavaInterface.java:470)
    Failed to start the Desktop: Failure loading desktop class

Leave a Comment