Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

How do I change the Java Virtual Machine (JVM) that MATLAB is using?


Date Last Modified: Thursday, October 29, 2009
Solution ID:   1-1812J
Product:   MATLAB
Reported in Release:   No Release
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How do I change the Java Virtual Machine (JVM) that MATLAB is using?

Problem Description:

I would like to use a different version of JVM than the default used in MATLAB.

Solution:

Instructions on changing the Java Virtual Machine is available in the MATLAB documentation. You can open the documentation page by executing the following command:
web([docroot,'/techdoc/matlab_external/f98533.html#f122001'])
or on the web at:


http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f98533.html#f122001

MATLAB is only fully supported on the JVM that we ship with MATLAB. For example:

JVM 1.3.1 for MATLAB 6.5.1 (R13SP1)

JVM 1.4.2 for MATLAB 7.0.1 (R14SP1)

MATLAB 7.0.4 (R14SP2) and later versions till MATLAB 7.4 (R2007a) use JVM 1.5 and MATLAB 7.5 (R2007b) and later use JVM 1.6. There are components that may not work properly under a different version of the JVM.

On Windows and Unix/Linux, in order to change the JVM which MATLAB is using, you will need to set the MATLAB_JAVA environment variable to point to the path of your JVM. On Mac, the MATLAB_JAVA environment variable *cannot* be used to modify the JVM that is being used by MATLAB.

The steps needed for making the change on the Windows platform are listed below:

To download the Java Virtual Machine, go to the following website:

http://java.sun.com/j2se/downloads.html

If you are using Linux, go to the following website, select the appropriate version of the JRE (Java Runtime Environment), and ensure that your operating system version is supported by this version of the JRE by checking the "Supported System Configurations":

http://java.sun.com/javase/downloads/previous.jsp

For Windows NT/2000/XP:
********************************
1. Click on Settings in the Start Menu
2. Choose Control Panel
3. Click on System
4. Choose the "Environment" tab (NT) or the "Advanced" tab and the "Environment Variables..." button.
5. In here you can set (or add) the MATLAB_JAVA system environment variable to the path of your JVM.


For Windows 95/98/ME:
*****************************
1. Open the AUTOEXEC.BAT file in your favorite text editor.
2. Add a line that reads

SET MATLAB_JAVA=D:\jre
For example, replace "D:\jre" with the directory in which your JRE is installed. Make sure not to have any unnecessary spaces when specifying this environment variable.

For UNIX/Linux:
*******************
On Unix csh or tcsh shells use the SETENV command to set the MATLAB_JAVA environment variable. For example:

setenv MATLAB_JAVA <path to JVM>

On Unix bash shell: In the shell, type:
export MATLAB_JAVA=/usr/java/jre1.6.0_07/

There are two ways to have a JVM installed: a JRE (the runtime), or a JDK (the runtime plus a development environment). The MATLAB_JAVA variable should point to the root of the RUNTIME, which may actually be in a subdirectory of the full JDK. Here is how to figure that out, along with some examples:

Find the file named rt.jar under your Java installation. (If that file doesn't exist, look for classes.zip). The directory that contains the directory that contains that file is the one that you need. For example,

On Windows:
****************
If the JDK is installed in D:\jdk1.2.1, the rt.jar file in that installation is D:\jdk1.2.1\jre\lib\rt.jar. So, the directory that contains the rt.jar file is D:\jdk1.2.1\jre\lib, and the directory that contains *that* directory is D:\jdk1.2.1\jre. So, the MATLAB_JAVA variable should point to D:\jdk1.2.1\jre.

On the other hand, if the JRE is installed in D:\jre1.3, the rt.jar in that installation is D:\jre1.3\lib\rt.jar. So, again, the directory is D:\jre1.3\lib, and the directory that contains THAT one is D:\jre1.3\, so you should set D:\jre1.3 as the value of MATLAB_JAVA.

On Unix:
**********
If the JDE is installed in /usr/openv/java/jre/lib, the rt.jar in that installation is /usr/openv/java/jre/lib/rt.jar. So the directory that contains the file is /usr/openv/java/jre/lib, and the directory that contains *that* directory is /usr/openv/java/jre. This means the MATLAB_JAVA variable should point to /usr/openv/java/jre.

On Macintosh:
*****************
**Please note that this is not the recommended way of updating java on a Mac System**

On Macintosh, MATLAB always uses the "A" (or the default) version of the JVM installed on the computer. To use a different version of JVM, you must specify the JAVA_JVM_VERSION environment variable.

For example, MATLAB 7.1 (R14SP3) uses JVM version 1.4.2 on Macintosh. To use a new version of the JVM, e.g. version 1.5, you must set the JAVA_JVM_VERSION to 1.5 as follows:

In tcsh:
setenv JAVA_JVM_VERSION 1.5

In bash:
export JAVA_JVM_VERSION=1.5

To verify which version of Java MATLAB is running, type the following at the MATLAB prompt:
version -java

Some customers have also found that on OS X the JVM is controlled not by these environment variables, but by the Java Preferences App :

Applications/Utilities/Java/Java Preferences.App

Here you can drag the Java version higher on the list and MATLAB should be able to pick that up at startup.

For reverting back to previous java runtime, customers have found following discussions useful.

http://discussions.apple.com/thread.jspa?threadID=1936578&tstart=1

Also see the Related Solution listed below.

 

Related Solutions:

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page