Matlab compiled using mcc for Windows cannot find java functions

Hi
I am using R2026a and I am trying to compile some scripts using mcc so I can run them standalone on a Windows 11 machine. My scripts include calls to some Java methods and no matter what I try the compiled code fails. I have realised that the mcc output no longer includes a JRE so I have tried both the Adoptium Temurin Java 21 JRE and the Adoptium Temurin Java 8 JDK, running matlab_jenv -allusers system at the Windows command prompt.
To investigate I have tried the following simple example saved as javaTest.m:
jenv
s = java.lang.String('Hello World');
fprintf (1, 'string is %s\n', s);
Running this within MATLAB gives
>> javaTest
ans =
JavaEnvironment with properties:
Version: "Java 1.8.0_492-b09 with Temurin OpenJDK 64-Bit Server VM mixed mode"
Home: "C:\Program Files\Eclipse Adoptium\jdk-8.0.492.9-hotspot\jre"
Library: "C:\Program Files\Eclipse Adoptium\jdk-8.0.492.9-hotspot\jre\bin\server\jvm.dll"
Status: loaded
Configuration: "system"
string is Hello World
>>
Compiling my script using
mcc -m javaTest.m
And then running at a windows command prompt I get
PS D:\Test> .\javaTest.exe
ans =
JavaEnvironment with properties:
Version: "openjdk version "1.8.0_492""
Home: "C:\Program Files\Eclipse Adoptium\jdk-8.0.492.9-hotspot\jre"
Library: "C:\Program Files\Eclipse Adoptium\jdk-8.0.492.9-hotspot\jre\bin\server\jvm.dll"
Status: notloaded
Configuration: "system"
MATLAB requires a Java Runtime Environment to run the command 'java.lang.String'.
Error in javaTest (line 2)
Caused by:
Unable to resolve the name 'java.lang.String'.
MATLAB:undefinedVarOrClass
PS D:\Test>
How can jenv correctly identify the Java environment and then literally on the next line the code fail because it doesn't think there is one? The results are essentially the same for both JDK 8 and JRE 21. Any suggestions would be welcome.
Thanks in advance.

1 Comment

Are the libraries for runtime and JRE on the system path? When launched, the app is in its own shell and the MATLABPATH isn't available plus the runtime.
I find the doc on setup less than helpful, too.
If the above doesn't resolve the issue contact Mathworks as an official support request at <Product Support Page>

Sign in to comment.

Answers (0)

Categories

Products

Release

R2026a

Asked:

Tim
about 22 hours ago

Commented:

dpb
about 16 hours ago

Community Treasure Hunt

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

Start Hunting!