Main Content

jenv

Set Java path for MATLAB

Since R2021b

    Description

    example

    jenv(version) sets the Java® path to use the version included with MATLAB®, the default version on your system, or the version in a specified folder. 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.

    example

    jenv(version,"-allusers") sets the path for all users.

    je = jenv(___) additionally returns environment details as a JavaEnvironment object. Use this syntax with any of the input argument combinations in previous syntaxes.

    Examples

    collapse all

    Use the version of Java included with MATLAB.

    jenv factory
    

    Restart MATLAB to use the specified version.

    Then, verify the version.

    version -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.

    version -java

    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.

    jenv -allusers system
    

    Restart MATLAB to use the specified version.

    Then, verify the version.

    version -java

    Input Arguments

    collapse all

    Java version, specified as a string or a character vector with one of these values:

    • "factory" — Version included with MATLAB

    • "system" — Default version on your system

    • Custom Java path — Folder to an installed Java on your computer

    The function selects the default value for "system" based on platform. If the selected version is incompatible with MATLAB, then MATLAB starts without the ability to use Java or any features that use Java. For information about Java versions compatible with MATLAB, see MATLAB Interfaces to Other Languages.

    • Windows® platforms — The function selects the supported Java version available on the Windows PATH or the registry. The Java might be Oracle® JRE™ or OpenJDK® JRE.

    • Linux® platforms — The function selects the supported Java version available on the system path. The Java might be Oracle or OpenJDK Java.

    • macOS platforms — The function selects the supported Java version based on one of these macOS java_home scripts:

      /usr/libexec/java_home -f -v 1.8
      /usr/libexec/java_home -f -v 1.11

    Example: jenv("system")

    Example: jenv("/usr/local/jre") for OpenJDK JRE on Linux and macOS

    Tips

    Version History

    Introduced in R2021b

    expand all