I would like to use a different version of JVM than the default used in MATLAB for Mac OS.
MATLAB ships with one specific version of the JVM software for MATLAB Releases R2013b (8.2) and later on Mac OS® X operating systems . For MATLAB Releases R2013a (8.1) and earlier on Apple Mac OS® X operating systems MATLAB uses the JVM that is available for all applications.
MATLAB is fully supported only on these shipped versions of the JVM software. Some components might not work properly under a different version of the JVM software. For example, calling functions in a dynamically linked library that was created with a different JVM software version than that used by MATLAB might cause a segmentation violation error message.
If you choose to change the JVM software version used by MATLAB, you must:
1. Download and install the desired version of the JRE (Java Runtime Environment) or the JDK (Java Development Kit). The latter contains the JRE and development tools.
2. Determine the path of the JRE directory within that installation. This varies by platform and whether you downloaded the JRE or JDK (see below).
3. Set the MATLAB_JAVA environment variable to this path (see below).
4. Start MATLAB while that environment variable is set (see below).
This article applies only to MATLAB launched from a shell window or modified shortcut as both of these methods set-up the MATLAB_JAVA variable. Clicking on the regular MATLAB icon will not use the new Java.
Setting MATLAB to use new Java
As an alternative to using the Terminal to start MATLAB using the new Java, you can download the attached "createMATLABShortcut" script and run it in MATLAB. This will create a shortcut on the Desktop to start MATLAB with the updated JRE. By default it will use the JRE from:
This new shortcut can be dragged onto the Dock for easier access.
If you would rather use Terminal to start MATLAB using the new Java, follow these steps:
Use the Finder to locate the JRE path. The JRE path will be similar to one of the following, depending on whether you have installed the JDK or just the JRE:
Note that if the JRE path contains spaces as in the 2nd case above, you must enclose it in quotes in the steps below.
Open a window in Terminal and execute:
to determine what shell you are using.
On csh or tcsh shells, use the "setenv" command to set the MATLAB_JAVA environment variable. For example:
setenv MATLAB_JAVA <JRE path>
This command needs to be run in every new shell window.
On the bash shell, execute:
export MATLAB_JAVA=<JRE path>
This setting will apply to MATLAB launched from that shell window.
Verifying the Installation
To verify that MATLAB is using the correct version of the JVM software, type the following at the MATLAB prompt:
>> version -java
If MATLAB is not using your value of MATLAB_JAVA, you may need to logout and log back in again.
To change the JVM MATLAB uses for other systems, use the following links.
There's a missing bit in the answer above, which is how do get the MATLAB_JAVA setting to stick after a reboot and work with the GUI version.
Following the advice in a StackExchange answer, the way to do this is under OS X (I'm using Mavericks, but it might work under previous releases as well):
1) Create a new file called called matlab.props.plist under /Library/LaunchDaemons (I don't think the name is important as long as it ends in .plist):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>matlab.props</string> <key>ProgramArguments</key> <array> <string>launchctl</string> <string>setenv</string> <string>MATLAB_JAVA</string> <string>/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home</string> </array> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> <key>LaunchOnlyOnce</key> <true/> </dict> </plist>
2) Replace the /Library/Internet... etc string with the path to the location of the JRE you have installed, if different.
3) Save the file.
5) Check the results by either doing 'launchctl getenv MATLAB_JAVA' in a terminal and/or 'version -java' from within MatLab.
To start Matlab without blurry fonts under OS 10.9 Mavericks without adding any configuration files:
MATLAB_JAVA="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"; open /Applications/MATLAB_R2013b.app/ons/MATLAB_R2013b.app/
Is this solution still valid? I have installed the 1.7 JDK successfully and OSX 10.9 reports it as the default version being used:
$ java -version java version "1.7.0_45" Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
I have followed these instructions and set the MATLAB_JAVA environment variable to:
However, running version -java in Matlab (R2013a) returns the old 1.6:
Java 1.6.0_65-b14-462-11M4609 with Apple Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
Any suggestions? Or has this solution become not possible?
I tried to put in the startup.m file
then added the .plist file with the above path. After rebboting, I still didn't get any result and I decided to directly set it from the prompt shell with :
launchctl setenv MATLAB_JAVA /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
then typed :
launchctl getenv MATLAB_JAVA
getting the jre path. However, after the reboot the above command returns a null result.
On Mac OS 10.9, you can put launchd commands in /etc/launchd-user.conf. Mine has
setenv JAVA_HOME /Library/Java/Home setenv MATLAB_JAVA /Library/Java/Home/jre
with symlinks set appropriately. (I develop native Mac GUI apps for a living, and can verify that all processes properly inherit these environment variables. I've tested it.
Unfortunately, I have many native java apps on my system, and they all work with this environment setup... all except matlab.
Starting Matlab 2013a:
Failed to create resources from application bundle. Using Java-based resources. java.lang.NullPointerException at java.io.File.<init>(File.java:222) at com.apple.resources.LoadNativeBundleAction.run(MacOSXResourceBundle.java:60) at com.apple.resources.LoadNativeBundleAction.run(MacOSXResourceBundle.java:33) at java.security.AccessController.doPrivileged(Native Method) at com.apple.resources.MacOSXResourceBundle.getMacResourceBundle(MacOSXResourceBundle.java:29) at com.apple.resources.MacOSXResourceBundle.getMacResourceBundle(MacOSXResourceBundle.java:24) at com.apple.laf.AquaLookAndFeel.initResourceBundle(AquaLookAndFeel.java:244) at com.apple.laf.AquaLookAndFeel.initComponentDefaults(AquaLookAndFeel.java:260) at com.apple.laf.AquaLookAndFeel.getDefaults(AquaLookAndFeel.java:227) at javax.swing.UIManager.setLookAndFeel(UIManager.java:520) at javax.swing.UIManager.setLookAndFeel(UIManager.java:564) at com.mathworks.mwswing.plaf.PlafUtils.setLookAndFeel(PlafUtils.java:296) at com.mathworks.mwswing.MJStartupForDesktop.init(MJStartupForDesktop.java:58) at com.mathworks.mwswing.MJStartupForDesktop.<clinit>(MJStartupForDesktop.java:32) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:171) at com.mathworks.util.PostVMInit$StartupClass.init(PostVMInit.java:96) at com.mathworks.util.PostVMInit.perform(PostVMInit.java:114) >> getenv('MATLAB_JAVA')
>> version -java
Java 1.6.0_65-b14-462-11M4609 with Apple Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
From the command-line (or any GUI app):
> java -version java version "1.7.0_45" Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
Hi everyone. A few questions:
1.) So what about Matlab 2013b, does it also NOT come shipped with its own Java?
2.) If that's the case, do I NEED to have 64 bit JVM installed on my computer in order to use 64bit Matlab? (I realize this is most likely a stupid question but just double checking.)
3.) If the answer to #1 is, "No, it did come shipped with its own JVM", then how do I set Matlab to use its own JVM instead of trying to use the one installed with the OS?
I just installed matlab 2013b, and this is the error I am getting:
Clearly, Matlab is looking in the wrong place, because my Java (32 bit) is actually installed in Program Files (x86). But if Matlab ships with its own Java, how do I make it use its own instead?
Just to add to this, after using the stock java for a while I noticed frequent 'beach balling' in OS X when zooming in figures. So it seems like the option here is to have sharp fonts (you know, like it's the XXI century) or having non-freezing program.
It's just amazing that after all these months Mathworks hasn't ported the java fixes back to their version and released a fix.
I am using MATLAB R2014a on MacOS 10.9 Mavericks, installed on a MacBookPro with retina display. I have Java 1.7.0_51-b13 installed on my system.
Setting the environment variable MATLAB_JAVA in a terminal, and starting MATLAB from this terminal worked, but I wanted this change also to apply on the GUI that I start by clicking on the MATLAB application with the mouse.
Since none of the solutions described here worked for me, I did the following:
I edited the file
(as root), and included the line:
setenv MATLAB_JAVA /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Note the backslash to make the space in the folder name work. (Quotes in this file do not seem to do the job.) I am using Lucida Sans Typewriter 9 point, and it renders beautifully with full resolution on the retina display.
After trying every available fix out there for this issue with no success, I think I came up with a very good answer for someone who likes to avoid the terminal (like me). It goes as follows:
MATLAB Retina Fix
Hope this helps, I am a novice when it comes to using the terminal, so to fix this problem by just copy-pasting seems much simpler
Hi. I have this problem in Ubuntu when I replace contanining of matlab path jre with 1.6 version of jre. what should I do ? I want downgrade from 1.7 to 1.6. When I run matlab R2014a I have this :
Fatal Error on startup: Cannot locate or initialize class com/mathworks/jmi/OpaqueJavaInterface. java.lang.UnsupportedClassVersionError: com/mathworks/jmi/OpaqueJavaInterface : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)