configure Java path for MATLAB, MATLAB Runtime and deployed applications

67 views (last 30 days)
MATLAB ships with one specific version of the JRE. This version is validated and fully supported with MATLAB.
However, you can configure MATLAB to use other version of JRE by following this article. Since R2021b, jenv and matlab_jenv commands are introduced to set Java path for MATLAB, which makes this configuration process much easier. 
If I used either command and configured MATLAB to use a non-default JRE, how will it impact deployed applications that this MATLAB compiles?
Can I configure JRE for MATLAB Runtime?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 Sep 2025 at 0:00
Edited: MathWorks Support Team on 24 Sep 2025 at 15:57

MATLAB Runtime JRE setting

MATLAB Runtime also has a JRE setting and its value can be changed by running the "matlab_jenv -allusers <version>" command from <runtime root>\bin.  Note, please make sure you are executing the command from <runtime root>\bin. Otherwise, if you have both MATLAB and MATLAB Runtime installed on one machine, you are changing MATLAB JRE setting instead of Runtime JRE setting if you execute the command directly. Because the matlab_jenv command under <MATLAB root>\bin will be executed without the folder specification. 
Executing <runtimeroot>\bin\matlab_jenv without -allusers flag may not issue errors but is not effective to anything.

Deployed application JRE setting

When compiling a deployed application, the application's JRE setting depends on how JRE was set for the current MATLAB session:
  • JRE setting sets with "-allusers" flag doesn't get included in the deployed application.
  • JRE settings sets without "-allusers" flag
    • R23b and higher: the setting gets removed if it is non-factory value. A warning is issued during mcc compile time . For example, if  jenv is set to a custom path, you will see warning
      "Your personal MATLAB preferences are set to use a version of Java installed on this system at <path>. This preference setting has been removed."
    • R23a and lower: The setting value from the MATLAB session that compiles the app will be included in the deployed app. During compiling time, mcc warns you about the non-factory JRE setting.
      Warning: Your MATLAB preferences are set to use a version of Java installed on this system at <path>. Users of this application may not have the same version of Java installed on their system causing the application to fail.

What JRE setting is my deployed application running with?

  • If the deployed application has a JRE setting included as described in above section, it will run against this setting.
    • R2023b or higher releases deployed application JRE sets to "factory": application run against factory JRE setting
    • R2023a or lower releases, deployed application JRE sets to:
      1. a custom JRE path: The same JRE must be installed in the same directory on the target machine. Otherwise the app will fail and errors "Unable to find Java library", "Java Runtime Not Found" or "Failed to initialize Java". To get rid of this error,
        • install the same custom JRE in the same directory on the target machine as on the MATLAB Developer's machine.
        • Or on the MATLAB Developer's machine, set JER setting to "system" or "factory" and recompile the application.
      2. "system": system JRE setting on the target machine, which may not be the same system value on the developer's machine.
      3. "factory": factory JRE setting.
  • If the deployed application doesn't have a JRE setting included, it will run against the MATLAB Runtime JRE setting, which could be factory or whatever has been set with <runtime root>\bin\matlab_jenv.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!