MATLAB: Does an application which uses Java and was generated by the MATLAB Compiler 4.0 (R14) fail to run when I deploy it to a new system

classclasspath.txtcom.mathworks.toolboxcompileddatabasedatabase.jarjarjavaMATLAB Compiler

I have an application generated by the MATLAB Compiler 4.0 (R14) which calls into a Java class. When I deploy it to a target computer I receive the following error:
Undefined variable "com" or class "com.mathworks.toolbox.<classname>".
MATLAB:UndefindedVarOrClass
I do not receive this error on the development system.

Best Answer

This bug has been fixed for Release 14 SP1 (R14SP1). For previous releases, please read below for any possible workarounds:
This error occurs because the compiled application fails to correctly set the CLASSPATH variable to point to the JAR-files which are included in the associated CTF-file (and extracted to the corresponding $APPNAME_mcr directory where $APPNAME is the name of your application). At runtime, the application is searching for the JAR-file in $MCR, the directory in which MCRINSTALLER was installed instead of the directory $APPNAME_mcr.
This error has been fixed in MATLAB Compiler 4.1 (R14SP1) and later.
In order to resolve this with version 4.0 (R14), extract the CTF-file either with the extractCTF utility described at:
Extracting a CTF Archive without Executing the Component :: Deployment Process (MATLAB Compiler)
or by running the application once and allowing it to error.
Copy the JAR-file referenced in the error message from its location in $APPNAME_mcr ($APPNAME_mcr/java/jar/toolbox for MATLAB toolboxes) to the corresponding location in $MCR (most likely $MCR/MATLAB Component Runtime/v70/java/jar/toolbox).
When you run your application, it will find the JAR-file in the $MCR directory.