JavaPackage plotting to file issue

3 visualizaciones (últimos 30 días)
Alex King
Alex King el 28 de Jul. de 2023
Respondida: Sugandhi el 21 de Ag. de 2023
I am compiling matlab to java as a jar package. I am getting errors when the plotting routines try to generate plots. It seems that when the java object is executed, and the script gets to the point where it is trying to generate the plots, the matlab runtime is envoking trying to envoke the mwswing libraries in the <matlabroot>/java/jar folder. When running my java application with -cp <matlabroot>/java/jar/*, the plotting routines seem to get further, but then throw an exception (see below). Is there something I missed when using compiler.build.JavaPackageOptions and compile.build.javaPackage that would ensure the appropriate jars from matlab are included in my generated jar file?
Exception in thread "AWT-EventQueue-0" java.lang.IllegalAccessError: superclass access check failed: class com.mathworks.hg.peer.types.HGMotifCheckMenuUI (in unnamed module @0x6166e06f) 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 @0x6166e06f

Respuestas (1)

Sugandhi
Sugandhi el 21 de Ag. de 2023
Hi Alex,
I understand that you getting errors when the plotting routines try to generate plots.
It seems that the issue you're facing is related to the fact that the MATLAB runtime is trying to use the MWJclipse libraries, which are not included in the Java package generated by the `compiler.build.JavaPackageOptions` and `compile.build.javaPackage` commands.
One of the possible workarounds is to add the 'MWJclipse' libraries to the Java package. You can do this by specifying the `-R` option when running the `javaPackage` command. The `-R` option tells the compiler to include all required runtime libraries in the package.
Here's an example of how you can modify your `build.m` file to include the MWJclipse libraries in the Java package:
% Build the Java package
javac -d build -sourcepath src -R -cp <matlabroot>/java/jar/* mypackage.java
In this example, the `-R` option tells the compiler to include all required runtime libraries in the package. The `-cp` option specifies the classpath for the MWJclipse libraries.
Alternatively, you can also specify the `-R` option when running the `javaPackage` command:
% Build the Java package
javaPackage -R -cp <matlabroot>/java/jar/* mypackage

Categorías

Más información sobre Java Package Integration en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by