jenv - Set Java path for MATLAB - MATLAB (original) (raw)
Main Content
Set Java path for MATLAB
Since R2021b
Syntax
Description
To configure the JRE™, choose either the jenv version
syntax for a single user account or the jenv -allusers version
syntax for the MATLAB® installation.
jenv([version](#mw%5F6e52d3e7-cd96-4217-9a6f-54427adb66eb))
sets the Java® path to use the version included with MATLAB, a version on your system, or the version in a specified folder. For supported version information, see MATLAB Interfaces to Other Languages. For more information, see Configure Your System to Use Java. You must restart MATLAB to use the updated path.
This function sets the path for all future MATLAB sessions but does not change the path for other applications on your computer.
jenv("-allusers",[version](#mw%5F6e52d3e7-cd96-4217-9a6f-54427adb66eb))
sets the path for all users. The jenv version
syntax takes precedence over thejenv -allusers version
syntax.
je = jenv(___)
additionally returns environment details as a JavaEnvironment object. Use this syntax with any of the input argument combinations in previous syntaxes.
Examples
Use Java Included with MATLAB
Use the version of Java included with MATLAB.
Restart MATLAB to use the specified version.
Then, verify the version.
Use Specific Installed Java
Use the version of Java installed at C:\Program Files\Java\jre1.8.0_202
.
jenv("C:\Program Files\Java\jre1.8.0_202")
Restart MATLAB to use the updated path.
Then, verify the version.
Use System Java for All Users
If you have administrator privileges, you can specify the Java version used by all users.
Start MATLAB with administrator privileges. Specify for all users to use the version of Java on their system.
Restart MATLAB to use the specified version.
Then, verify the version.
Input Arguments
version
— Java version
"factory"
(default) | "system"
| custom Java path
Java version, specified as a string or a character vector with one of these values:
"factory"
— Version included with MATLAB"system"
— Searches your system for a supported version 8. If not found, it searches for version 11, then for version 17. The search is based on platform.- Windows® platforms:
1.java -version
system command
2. Registry entries - Linux® platforms:
1.JAVA_HOME
environment variable
2. System path - macOS platforms:
1./usr/libexec/java_home -f -v 1.8
2./usr/libexec/java_home -f -v 11
3./usr/libexec/java_home -f -v 17
- Windows® platforms:
- Custom Java path — Folder to an installed Java on your computer
For information about Java versions compatible with MATLAB, see MATLAB Interfaces to Other Languages.
Example: jenv("system")
Example: jenv("/usr/local/jre")
for OpenJDK® JRE on Linux and macOS
Tips
- To use the OpenJDK JRE, download the software from https://adoptium.net/.
Version History
Introduced in R2021b
R2023a: Return environment information
The function returns a JavaEnvironment object, which contains information about the Java program on your system.