MATLAB: Compiled application only runs on the compiling machine

compiler; javaMATLAB Compiler

I have a strange situation where an application compiled on machine #1 only runs on #1 and not on #2. If I compile on #2, it then runs on #2 but not on #1.
The error I get seems similar to an issue that was fixed in R2014 – Arguments to IMPORT must either end with ".*" or else specify a fully qualified class name: "com.mongodb.MongoClient" fails this test. I've tried using the .*, I've tried not using import and using the fully qualified name instead, all of these run on the compiling machine but not on any other.
Has anybody encountered this problem as well? Any suggestions?
————————————————————–
I've copied the PackagingLog.html file below:
mcc -o DAP -W WinMain:DAP -T link:exe -d C:\Users\oerc0003\Dropbox\Projects\DIET\DAP\DAP\DAP\for_testing -v C:\Users\oerc0003\Dropbox\Projects\DIET\DAP\DAP\dap.m -a 'C:\Users\oerc0003\Documents\MATLAB\Add-Ons\Toolboxes\GUI Layout Toolbox\code\layout\+uix\Resources' -r 'C:\Program Files\MATLAB\R2017b\toolbox\compiler\Resources\default_icon.ico'
Compiler version: 6.5 (R2017b)
Dependency analysis by REQUIREMENTS.
[Warning: Package directories not allowed in MATLAB path:
C:\Users\oerc0003\Documents\MATLAB\Add-Ons\Toolboxes\GUI Layout
Toolbox\code\layout\+uix\Resources]
Parsing file "C:\Users\oerc0003\Dropbox\Projects\DIET\DAP\DAP\dap.m"
(Referenced from: "Compiler Command Line").
Deleting 0 temporary MEX authorization files.
Generating file "C:\Users\oerc0003\Dropbox\Projects\DIET\DAP\DAP\DAP\for_testing\readme.txt".
Packaging...
Creating the bundle...
Self contained installer created at C:\Users\oerc0003\Dropbox\Projects\DIET\DAP\DAP\DAP\for_redistribution\MyAppInstaller_mcr.exe.
Packaging complete.
Elapsed packaging time was: 50 seconds.

Best Answer

It's due to Java class path difference of MATLAB and deployed environment. You need to add Java class path in deployed application. Please see this link.
Edited: I've reproduced the same error using MATLAB / MATLAB Runtime R2017a, the same jar files (bson-3.4.2.jar, mongodb-driver-3.4.2.jar, mongodb-driver-core-3.4.2.jar) on Windows 10 machines. Machine #1 is MATLAB, machine #2 is MATLAB Runtime only. I solved by adding jar files on machine #2 and adding classpath.txt under MCRROOT\toolbox\local where MCRROOT is MATLAB Runtime installation folder. To use jar libraries on deployed MATLAB Runtime environment, you need to (1) add the jar files to m files when compiling, or (2) copy the jar files on the deployed machine and add jar file paths on classpath.txt.
I hope this works.