Library compiler java package error
이전 댓글 표시
I am trying to use the library compiler to generate a java package for matlab functions. And I select all the functions with an existing sample.
But I am facing the below error and no files are generated in xxxx/for_redistribution_files_only\samples.
com.mathworks.mvm.exec.MvmExecutionException: compiler.internal.ExampleParser.getArgumentValidation
at com.mathworks.mvm.exec.NativeFutureResult.nativeGet(Native Method)
at com.mathworks.mvm.exec.NativeFutureResult.get(NativeFutureResult.java:62)
at com.mathworks.mvm.exec.FutureResult.getInternal(FutureResult.java:413)
at com.mathworks.mvm.exec.FutureFevalResult.getInternal(FutureFevalResult.java:49)
at com.mathworks.mvm.exec.FutureResult.get(FutureResult.java:263)
at com.mathworks.toolbox.compiler_examples.generation.ExampleValidator.validateExample(ExampleValidator.java:41)
at com.mathworks.toolbox.compiler.plugin.PackageCommand$3.iterate(PackageCommand.java:416)
at com.mathworks.project.impl.plugin.XmlReaderImpl.loop(XmlReaderImpl.java:232)
at com.mathworks.toolbox.compiler.plugin.PackageCommand.packageSamples(PackageCommand.java:409)
at com.mathworks.toolbox.compiler.plugin.PackageCommand.execute(PackageCommand.java:676)
at com.mathworks.project.impl.engine.DeploymentEngine.executeScript(DeploymentEngine.java:373)
at com.mathworks.project.impl.engine.DeploymentEngine.access$000(DeploymentEngine.java:44)
at com.mathworks.project.impl.engine.DeploymentEngine$2.run(DeploymentEngine.java:289)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.mathworks.mvm.exec.MvmRuntimeException: Reference to a cleared variable this.
Error in ==> C:\Program Files\MATLAB\R2020b\toolbox\compiler_sdk\java\+compiler\+internal\ExampleParser.p>ExampleParser.getVariables at 0
Error in ==> C:\Program Files\MATLAB\R2020b\toolbox\compiler_sdk\java\+compiler\+internal\ExampleParser.p>ExampleParser.getArgumentValidation at 0
답변 (1개)
Kojiro Saito
2021년 7월 8일
편집: Kojiro Saito
2021년 7월 8일
I can reproduce this issue if sample m script contains clear all.
Reproduction Step
addmatrix.m (to be compiled as Java package)
function out = addmatrix(in1, in2)
out = in1 + in2;
end
addmatrixWithClearSample2.m (sample m file which calls addmatrix)
clear all;
in1 = 0; % Initialize in1 here
in2 = 0; % Initialize in2 here
out = addmatrix(in1, in2);
Add addmatrixWithClearSample2.m from "Add Existing Sample" in Samples panel of Library Compiler window.

When packaging, we'll get "Caused by: com.mathworks.mvm.exec.MvmRuntimeException: Reference to a cleared variable this." error as you provided.
Solution
Remove or comment out "clear all" in your sample script. In the above example, addmatrixWithClearSample2.m should be the following.
addmatrixWithClearSample2.m
%clear all; % Comment out
in1 = 0; % Initialize in1 here
in2 = 0; % Initialize in2 here
out = addmatrix(in1, in2);
카테고리
도움말 센터 및 File Exchange에서 Deploy to Java Applications Using MWArray Data API에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!