I get an error message while using a JAR that is compiled by Library Compiler

4 views (last 30 days)
I have a MATLAB project, which I compile using the MATLAB compiler to a JAR file and call from a Java project. I have been using the compiled file on Windows without any issues for a few years. Recently, I switched to Mac. Today, I decided to compile my Java project on Mac OS Sequoia. I compiled the MATLAB code on my Mac Studio with M2 Max processor and added to my Java project as a library as usual. However, I get the following error when I try to plot a graph using it:
java.lang.UnsatisfiedLinkError: Can't load library: /System/Library/Frameworks/gluegen-rt.Framework/gluegen-rt
I couldn't resolve the problem despite spending several hours on it. Could you help me with this problem?

Accepted Answer

Mathias
Mathias on 6 Mar 2025
Edited: Mathias on 6 Mar 2025
Hi Cagri,
For some reason the "gluegen-rt.jar" library cannot be loaded, as the error states. This library should be found here: <matlabroot>\java\jarext\gluegen-rt.jar where 'matlabroot' is the directory you get after running >>matlabroot in MATLAB.
Here a few ideas:
Since this is a graphics-related issue, you might also want to try turning off 'OpenGL'. This will probably result in lesser graphics performance, but it might get your jar running again. To do so, when compiling your jar, set the -noopengl flag. How to set a flag when compiling is detailed here:
Alternatively, in your Java code, initialize the MATLAB runtime in the following way, so that "noopengl" is used:
MWApplication.initialize(new MWMCROption(){public String[] toStringArray(){return new String[] {"-noopengl"};}});
  1 Comment
Cagri
Cagri on 7 Mar 2025
Edited: Cagri on 7 Mar 2025
Thank you very much Mathias! My application is compiled as a library, so -noopengl flag didn't work, since it is for standalone applications. However, initializing the MATLAB runtime as you suggested worked like a charm.

Sign in to comment.

More Answers (0)

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!