- java.desktop/sun.awt
- java.desktop/sun.java2d
- java.desktop/com.sun.java.swing.plaf.motif
- java.desktop/com.apple.eawt
"IllegalAccessError" when I call MATLAB Compiler SDK Java library with Java 17 and versions above
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 10 Avr 2024
Modifié(e) : MathWorks Support Team
le 11 Avr 2024
I compiled my MATLAB function to a Java package with MATLAB Compiler SDK. When I call the package against Java 17 or versions above 17 runtime, the application fails with error below or similar.
"java.lang.IllegalAccessError: superclass access check failed".
For example, when I call a Java package that compiled the MATLAB plot function, I receive error:
Exception in thread "AWT-EventQueue-0": java.lang.IllegalAccessError: superclass access check failed: class com.mathworks.hg.peer.types.HGMotifCheckMenuUI (in unnamed module @0x6eb317bb) cannot access class com.sun.java.swing.plaf.motif.MotifMenuUI (in module java.desktop) because module java.desktop does not export com.sun.java.swing.plaf.motif to unnamed module @0x6eb317bb
Réponse acceptée
MathWorks Support Team
le 11 Avr 2024
Modifié(e) : MathWorks Support Team
le 11 Avr 2024
This error is due to encapsulation barriers introduced by the module system in Java, particularly for reflection-based access by libraries and frameworks. MathWorks' Java code accesses some non-public fields and methods of java.* packages.
To workaround the issue, please specify --add-opens option with the module and package name mentioned in the error message at runtime. For above example error message, the module is "java.desktop" and package is "com.sun.java.swing.plaf.motif". So the java command is
java -classpath .;"matlabroot\toolbox\javabuilder\jar\javabuilder.jar";.\<yourCompiledLibrary>.jar --add-opens java.desktop/com.sun.java.swing.plaf.motif=ALL-UNNAMED <yourJavaApp>
You can have multiple --add-opens options. Below packages are what we have discovered so far that may trigger this error. But this is not an exhaustive list.
To open all these packages, you can use below command:
java -classpath .;"matlabroot\toolbox\javabuilder\jar\javabuilder.jar";.\<yourCompiledLibrary>.jar --add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.java2d=ALL-UNNAMED --add-opens java.desktop/com.sun.java.swing.plaf.motif=ALL-UNNAMED --add-opens java.desktop/com.apple.eawt=ALL-UNNAMED <yourJavaApp>
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Java Package Integration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!