MATLAB Answers

0

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

Asked by MathWorks Support Team on 20 May 2014
Latest activity Commented on by Walter Roberson
on 9 Jul 2019 at 16:30
I would like to use a different version of JVM than the default used in MATLAB on Windows.

Tags

No tags entered yet.

4 Answers

Answer by MathWorks Support Team on 28 May 2019
Edited by MathWorks Support Team on 28 May 2019
 Accepted Answer

MATLAB ships with one specific version of the JVM software on Windows depending on the release. 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).
Setting MATLAB to use new Java
Make sure you download the 32 or 64-bit version of the JDK or JRE, depending on your platform. To determine which platform you have, you can issue the following in MATLAB:
>> computer(arch)
The JRE is at the parent directory of the directory that contains the file "rt.jar". For example, if "rt.jar" is at:
C:\Program Files\Java\jre6\lib\rt.jar
you should set the MATLAB_JAVA environment variable to:
C:\Program Files\Java\jre6
To set MATLAB_JAVA:
1. Click Start
2. Right click Computer and choose Properties
3. Click Advanced System Settings and then click the Environment Variables button.
4. In the system variables section, set (or add) the MATLAB_JAVA system environment variable to the JRE path determined above
This change takes effect on the next launch of MATLAB from an icon, or from a subsequently opened command prompt 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.
Other OS:
To change the JVM MATLAB uses for other systems, use the following links.
Linux:
Mac OS:

  4 Comments

Show 1 older comment
This procedure no longer works as of Java 9, as rt.jar has been removed: Java Platform, Standard Edition Oracle JDK 9 Migration Guide.
I have always been mildly concerned from a security standpoint that MathWorks ships an older JRE with Matlab. I hope MathWorks addresses this concern in future releases.
Is there no way to choose the newer JVM?
I tried setting MATLAB_JAVA to the path 'C:\Program Files\Java\jre-9.0.4' but I get this error: 'Unable to start JVM because of an invalid Java option'.

Sign in to comment.


Answer by Michael
on 20 Apr 2017

Hello,
I'm getting this error-message after setting up the new Java-Version:
Warning: An error occurred while reading the desktop configuration file. Using the default configuration. The desktop configuration was not saved successfully
Any suggestions about a fix?

  3 Comments

After set up the MATLAB's java to version jre1.8.0_121, I'm getting the same as Michael. Any solution about this?
I have the same and Matlab still display the correct new version for java when asked : version -java Unfortunately, I still can't do what I was supposed to do with java 8 running on Matlab : make Matlab and ImageJ communicate correctly.
version -java
ans =
Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot™ 64-Bit Server VM mixed mode the above version i have...and how to make guide to work...

Sign in to comment.


Answer by mohammadreza vali on 13 Oct 2015
Edited by Walter Roberson
on 13 Oct 2015

hello
plaese help
my windows is 8.1 32 bit
matlab 2011 in my pc is good
but in matlab 2015 after click F1, it shows
"""""""""""""""
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Could not initialize class com.mathworks.mlwidgets.help.ProductFilterModel$InstalledState
at com.mathworks.mlwidgets.help.DocCenterProductPrefs.getSelectedProductsFromPref(DocCenterProductPrefs.java:47)
at com.mathworks.mlwidgets.help.DocCenterProductPrefs.getProductFilterModel(DocCenterProductPrefs.java:33)
at com.mathworks.mlwidgets.help.DocCenterDocConfigParams.<init>(DocCenterDocConfigParams.java:37)
at com.mathworks.mlwidgets.help.DocCenterDocConfig.getLocalConfig(DocCenterDocConfig.java:77)
at com.mathworks.mlwidgets.help.DocCenterDocConfig.getInstance(DocCenterDocConfig.java:65)
at com.mathworks.mlwidgets.help.HelpPopup.createHelpPanel(HelpPopup.java:461)
at com.mathworks.mlwidgets.help.HelpPopup.createComponents(HelpPopup.java:451)
at com.mathworks.mlwidgets.help.HelpPopup.<init>(HelpPopup.java:447)
at com.mathworks.mlwidgets.help.HelpPopup.getInstance(HelpPopup.java:428)
at com.mathworks.mlwidgets.help.HelpPopup.closeIfShowingWithDifferentParent(HelpPopup.java:273)
at com.mathworks.mlwidgets.help.HelpPopup.showHelp(HelpPopup.java:386)
at com.mathworks.mlwidgets.help.HelpPopup.showHelp(HelpPopup.java:347)
at com.mathworks.mlwidgets.help.HelpPopup.showHelp(HelpPopup.java:229)
at com.mathworks.mlwidgets.help.HelpPopup.showHelp(HelpPopup.java:156)
at com.mathworks.mde.cmdwin.CmdWinEditorKit$HelpAction.actionPerformed(CmdWinEditorKit.java:1458)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at com.mathworks.mde.cmdwin.XCmdWndView.processKeyEvent(XCmdWndView.java:2461)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at com.mathworks.mde.cmdwin.XCmdWndView.processEvent(XCmdWndView.java:425)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
"""""""""""""""
plaese help me

  0 Comments

Sign in to comment.


Answer by Kapil Nagwanshi on 6 Mar 2018

Very Simple Solution!! Go to your jre folder C:\Program Files\Java\jre1.8.0_161 copy the content jre folder C:\Program Files\Java\jre1.8.0_161 paste it to 'C:\Program Files\MATLAB\R201XX\sys\java\jre' folder now it's ready to run with updated version

  5 Comments

After following this step, the error message changed to Unable to start the JVM because of an invalid Java option
What your solution for your problem ? My problem same with you
Desla Sari which operating system are you using? The methods for Mac are quite different than for Windows.

Sign in to comment.