Main Content

Use Java Runtime Environment (JRE) with MATLAB Runtime

MATLAB® Runtime will no longer include the JRE™ in a future release. If your deployed application uses Java® functionality, for instance, by calling Java methods from MATLAB code or by connecting to databases using JDBC, you must manually configure MATLAB Runtime to use a supported external JRE or Java Development Kit (JDK™).

To get started, first install a supported version of Java on your system. For a list of supported Java versions, see Versions of OpenJDK Compatible with MATLAB by Release.

After installing Java, run the matlab_jenv command from the operating system prompt to configure MATLAB Runtime to use your Java installation. This command is shipped with MATLAB Runtime and is located in <matlabroot>/runtime/bin.

Configure MATLAB Runtime to Use Default Java Installation

If you have a compatible version of Java installed in the standard location on your system, and it is the first Java entry on your system path, you can run the matlab_jenv command with the system option.

matlab_jenv -allusers system

This command configures MATLAB Runtime to use the default Java installed on your system.

Configure MATLAB Runtime to Use Custom Java Installation

To use a specific version of the JRE or JDK with MATLAB Runtime:

  1. Download and install a supported version of OpenJDK®. For more information, see Versions of OpenJDK Compatible with MATLAB by Release.

  2. Run the matlab_jenv command from the operating system prompt with the path to your Java installation. For example, to use OpenJDK version 17 installed in D:\Program Files\Eclipse Adoptium\jdk-17.0.16.8-hotspot, run:

    matlab_jenv "D:\Program Files\Eclipse Adoptium\jdk-17.0.16.8-hotspot"
  3. To verify the version of Java that MATLAB is configured to use (supported since R2023a), run:

    matlab_jenv

Troubleshooting

After configuring Java for MATLAB Runtime, you can verify the configuration by running an application that uses Java functionality. If Java is properly configured, the application should run without Java-related errors.

If your application displays an error about missing Java configuration:

  1. Ensure you have a compatible Java version installed

  2. Verify that you have correctly configured MATLAB Runtime using the matlab_jenv command

  3. Check that the specified Java path exists and contains a valid JRE or JDK installation

See Also

Topics