1. Add directory to the JAR file to <mcr root>\toolbox\local\javaclasspath.txt. This is not a recommended workflow.
2. Include a "javaclasspath.txt" file from preference folder in the compiled application (folder returned by "prefdir" command).
Before R2022a, the "javaclasspath.txt" file in the MATLAB preference folder was automatically packaged in the deployed application. If the JAR file on the target machine is in the same folder, you do not need to do anything. If the JAR file is placed in a different folder on the target machine, you need to modify the "javaclasspath.txt" file before packaging.
Starting in R2022a, MATLAB Compiler became more selective about which files to install from the user's preference folder into the deployed application. "javaclasspath.txt" and "javalibrarypath.txt" are not automatically included. To continue using "javaclasspath.txt", you need to explicitly add the file to the deployed application using the "mcc -a" option, or through the "deploytool" interface. Again, if the JAR file is placed in a different folder on the target machine, you need to modify the "javaclasspath.txt" file before packaging.
3. Use "javaaddpath" to add the JAR file directory on the target machine.
You can use the "isdeployed" function for the deployed app.
4. If you cannot install the jar file on the target machine:
Use the "mcc -a" option or "deploytool" interface to add the JAR file to the deployed application. JAR files added with "-a" option or "deploytool" are automatically added by "javaaddpath" during the initialization of the CTF file. This is the recommended approach as you do not need to install the jar file separately on the target machine and the users are guaranteed can access the JAR file.
javalibrarypath.txt
If you are using "javalibrarypath.txt" file to point to DLL files that are used in the application, you need to explicitly use the "mcc -a" option or "deploytool" to add the "javalibrarypath.txt" file from the preference folder. Note that it must be added from the preference folder so that it will also be packaged into the preference folder of the CTF file. In addition, you need to have the DLL files available on the target machine. Please refer to Approach (2) above for more details.