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 个)

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);

2 个评论

Thanks for the solution. After removing the clear all I am not facing this issue.
I am requesting you to Can you please have a look in the below issue and provide me the solution for this one also.
Thanks in advance

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Deploy to Java Applications Using MWArray Data API 的更多信息

产品

版本

R2020b

提问:

CHV
2021-7-7

评论:

CHV
2021-7-8

Community Treasure Hunt

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

Start Hunting!

Translated by