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

603 views (last 30 days)
I would like to use a different version of JVM than the default used in MATLAB on Windows.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 6 May 2022
Edited: MathWorks Support Team on 6 May 2022
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 path to the JRE directory.
  • For R2021b and later versions, use MATLAB's jenv or matlab_jenv command.
  • For R2021a and earlier versions, set the MATLAB_JAVA environment variable to this path, and start MATLAB while that environment variable is set.  See detailed instructions 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.
To revert back to the shipped version of the JVM software delete or unset the "MATLAB_JAVA" environment variable.
  4 Comments

Sign in to comment.

More Answers (4)

Michael
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
hp
hp on 9 Nov 2018
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.


Kapil Nagwanshi
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
  8 Comments
Walter Roberson
Walter Roberson on 24 Feb 2022
You are correct, the file path does look like what you show. MATLAB uses that style a few other places as well when there is operating system / architecture-specific contents.
The first 'jre' is sort of the "class" of what is underneath; then the win64 is the specific architecture, and then the second 'jre' is the top level folder for a subsystem. There are situations in which there might be multiple folders under the architecture. For example it is common for compilers to split into different directories for the parser (which might generate intermediate code), the code generator, and the linker.

Sign in to comment.


Ivan Carrasco
Ivan Carrasco on 20 Aug 2019
Edited: Ivan Carrasco on 20 Aug 2019
Set
C:\Program Files\MATLAB\R2017b\sys\java\jre\win64\jre
as
MATLAB_JAVA
on
Environment Variables
:-)

mohammadreza vali
mohammadreza vali on 13 Oct 2015
Edited: 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

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by