주요 콘텐츠

Use Java Runtime Environment (JRE) with MATLAB Runtime

R2026b

Starting in R2026b, MATLAB® Runtime no longer includes the JRE™. 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 ships with MATLAB Runtime and is located in the <MATLAB_RUNTIME_INSTALL_DIR>/bin folder.

Note

To run matlab_jenv, either add the bin folder to your system PATH or specify the full path to the command.

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 Runtime is configured to use (supported since R2023a), run:

    matlab_jenv

Configure MATLAB Runtime Container

Starting in R2026b, MATLAB Runtime container images no longer include the JRE. For more information about MATLAB Runtime containers, see MATLAB Runtime Containers.

To include Java in a standalone application Docker® image or a microservice image, use either the compiler.package.docker function or the compiler.package.microserviceDockerImage (MATLAB Compiler SDK) function. Specify the Ubuntu® Linux® software package to include using the AdditionalPackages name-value argument. To run the matlab_jenv command on the container, use the AdditionalInstructions name-value argument.

For example, package the MATLAB function usejava26b.m as a standalone application Docker image.

results = compiler.build.standaloneApplication('usejava26b.m');

compiler.package.docker(results,ImageName='usejava26b', ...
    AdditionalPackages='openjdk-17-jre', ...
    AdditionalInstructions='RUN /opt/matlabruntime/R2026b/bin/glnxa64/matlab_jenv -allusers system')

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 runs 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