필터 지우기
필터 지우기

JavaPackage plotting to file issue

조회 수: 5 (최근 30일)
Alex King
Alex King 2023년 7월 28일
답변: Sugandhi 2023년 8월 21일
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

답변 (1개)

Sugandhi
Sugandhi 2023년 8월 21일
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

카테고리

Help CenterFile Exchange에서 Java Package Integration에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by