Compiled matlab executables not working correctly with java archives

I have several programs that I wrote in matlab that use external custom java archives. The programs work fine on my computer (with the matlab license) (as .m files). They also work on the same computer as compiled executables with the main matlab install not running.
When I put them on another PC with the MCR installed (and the relevant libraries as checked/verified with non-matlab programs), the executables do not work. At best, they flash a quick empty figure window before terminating.
I have verified that the java archives appear to have the same paths on the new PC. I have also made a point of adding the directory containing the archives to the system OS path.
What could cause my compiled executables to fail to find and use my java archives? (Note: I have verified that executables not using the archives appear to work as expected, so the MCR is presumably installed correctly).
Thanks in advance, Sean

Answers (1)

In general, you are discouraged from using functions like ADDPATH with absolute paths from deployed applications. See Path Management in Deployed Applications. I think the solution for your case might be to add the required JAR-files to the CTF archive (using the mcc -a option) and then add them relative to ctfroot.

7 Comments

Perhaps I wasn't clear... I am not modifying paths in the actual code. My mention of adding a directory was to the OS environmental path variable (in the hopes that matlab was trying to find it there).
Right now my software works on the originating PC, but does not on a second PC with the MCR installed. I know the MCR works for entirely self-contained executables that don't use java archives.
I need to know how to find a way to either:
A)include the relevant code from the java archives and all relevant linkages into the compiled executable. (OR)
B)permit the compiled executable to successfully use the java archives installed on the PC.
Any help would be appreciated.
Thanks
BTW: I'm not clear on what the CTF archive is? I followed the link to 'ctfroot' in your post, but the contents of that link weren't entirely clear to me. If using this 'CTF archive' will let me carry the java archives in the executable without having to separately install them on the PC, that would be somewhere between acceptable and awesome.
Thanks again.
As far as I know, you need to use javaaddpath to add all paths to an JAR files to the MATLAB path (adding them to the System path is not enough). You can verify the MATLAB-Java path on the originating PC by running "javaclasspath" - you should see that the path where the JAR-files reside should be listed there.
I would recommend adding your JAR-files to the CTF and then use the javaaddpath command into your MATLAB code, and add "ctfroot" or $ctfroot/path/containg/JAR.
See an explanation about the CTF archive here: http://www.mathworks.com/help/releases/R2011b/toolbox/compiler/bsfey7f.html#bsfj66v-1
And yes, adding your JAR files to the CTF archive will let you package them with the executable.
Are you using deploytool to compile your MATLAB code? If yes, drag your JAR-files into the "Additional Files" section. That should package them into the CTF.
I have tried updating the classpath.txt file in ...\toolbox\local to include the paths for the two java archives. I was expecting that would work in terms of letting the code use the already installed java archives on the new PC. Unfortunately, there does not appear to have been any change in the behavior of the executable.
I have also tried adding the archives to the extra files section of the deploytool gui (and adding the text: addjavapath 'ctfroot'; ), but again did not see any change in behavior. The executables work on the source PC, but not on the new PC.
Sean: The command is "javaaddpath({[ctfroot 'customjavaarchive1.jar'], [ctfroot 'customjavaarchive2.jar']})" not "addjavapath 'ctfroot'".
Basically, javaaddpath can take a cell-array of strings representing the paths, so you can add additional strings to the cell-array I construct above (of course you need to replace customjavaarchive1.jar, etc. with the actual names of your JAR files.
Thanks for the clarification... Unfortunately, when I use the string "javaaddpath({[ctfroot 'DiagIF.jar'], [ctfroot 'AVIO.jar']});" at the beginning of the code and include the .jar files in the 'additional files' section, the results do not change.
Any further ideas?
Thanks in advance.
Oops, sorry, you need "javaaddpath({[ctfroot '/DiagIF.jar'], [ctfroot '/AVIO.jar']});". You need the "/" to separate the ctfroot path from your filename.

Sign in to comment.

Categories

Asked:

on 30 Jan 2012

Edited:

ES
on 7 Oct 2013

Community Treasure Hunt

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

Start Hunting!