Why do I get java class IMPORT errors when compiling a deployed application using MATLAB Compiler 4.16 (R2012a)?

8 views (last 30 days)
I have a MATLAB code that imports some java classes using IMPORT, as below:
import com.google.common.base.Stopwatch;
This code runs fine without issues in MATLAB, but when I try to deploy it using MCC or DEPLOYTOOL, I get the following error:  
Error: File: T:\1-GOVY7I\repro_import_build_error\repro_import_build_error\standalone_hello.m Line: 2 Column: 8
Arguments to IMPORT must either end with ".*"
or else specify a fully qualified class name: "com.google.common.base.Stopwatch" fails this test.
Processing include files...
2 item(s) added.
Processing directories installed with MCR...
The file mccExcludedFiles.log contains a list of functions excluded from the CTF archive.
2 item(s) added.
Generating MATLAB path for the compiled application...
Created 40 path items.
Begin validation of MEX files: Wed Feb 22 15:24:12 2012
End validation of MEX files: Wed Feb 22 15:24:12 2012
Parsing file "T:\1-GOVY7I\repro_import_build_error\repro_import_build_error\standalone_hello.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2011b\toolbox\compiler\deploy\deployprint.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2011b\toolbox\compiler\deploy\printdlg.m"
(Referenced from: "Compiler Command Line").
Unable to determine function name or input/output argument count for function
in MATLAB file "standalone_hello".
Please use MLINT to determine if this file contains errors.
Error using mcc
Error executing mcc, return status = 1 (0x1).
I have made sure that the java JAR files are on the dynamic java path and is available to MATLAB.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Jul 2017
This bug has been fixed in Release 2012b (R2012b). For previous product releases, read below for any possible workarounds:
This is a bug in MATLAB Compiler 4.16 (R2012a). Possible workarounds are:
1. Instead of using
 
import com.google.common.base.Stopwatch;
where the full class name is defined, use
 
import com.google.common.base.*;
2. It is also possible to encapsulate the IMPORT statements inside MATLAB Class objects, such as:
 
classdef someclass
methods
function helloworld(obj)
import com.google.common.base.Stopwatch;
disp('Hello, world!');
end
end
end
In this case, you still get the warning
Error: File: T:\1-GOVY7I\repro_import_build_error\repro_import_build_error\standalone_hello.m Line: 2 Column: 8
Arguments to IMPORT must either end with ".*"
or else specify a fully qualified class name: "com.google.common.base.Stopwatch" fails this test.
but the compilation will continue and generate a working component.
3. Add the java class JAR file into MATLAB's static java class path (instead of using JAVAADDPATH, which adds to dynamic class path). To do this, you need to add the JAR file path into MATLAB's classpath.txt file located at
matlabroot\toolbox\local\classpath.txt
where matlabroot is MATLAB's installation directory. Editing the classpath.txt file should be avoided if possible, as any mistake can cause MATLAB to crash upon startup.

More Answers (0)

Categories

Find more on Java Package Integration in Help Center and File Exchange

Products


Release

R2011b

Community Treasure Hunt

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

Start Hunting!