MATLAB: Do I get a warning stating “Invalid file or directory” when attempting to add a JAR-file to the dynamic Java class path in a deployable archive running on MATLAB Production Server

archivedeployablejavaaddpathjdbcMATLAB Production Servermpsproductionserver

My deployable archive (.ctf) requires JDBC drivers to interact with a database. However, when I add the JDBC JAR-file to the "Files required for your archive to run", compile the archive, and run it on MATLAB Production Server, I get a warning stating "Invalid file or directory" when attempting to add the JDBC driver JAR-file to my dynamic Java class path using the "javaaddpath" function. Why?

Best Answer

The "javaaddpath" function should not be used in deployed CTF-archives (or deployed applications in general). When a JAR-file is added to the "Files required for your archive to run" list, it will automatically be added to the dynamic path when the CTF-archive is loaded on MPS.
In cases where it is convenient to keep "javaaddpath" in the M-files when they run in MATLAB, one can use the "isdeployed" function to skip over calls to "javaaddpath" functions when run under deployment, as shown:
 
if ~isdeployed
javaaddpath('lib/jconn2.jar');
end