How do I set the Java classpath for stand-alone applications created using MATLAB Compiler?
22 views (last 30 days)
Show older comments
I am trying to call Java methods and objects from a stand-alone application compiled from an MATLAB file. It works fine on my development machine. I would like to know how to deploy it and also how to specify the classpath for the deployed application.
Accepted Answer
MathWorks Support Team
on 28 Jan 2010
The JAVAADDPATH command can be used to add Java classes to MATLAB's dynamic Java class path irrespective of whether the application is being deployed as a stand-alone application on a target machine or as a MATLAB function on the development machine. However, note that if an absolute path is used to specify the Java class path, make sure that the path exists on the target machine. As an example consider the following function:
function java_test()
javaaddpath('C:\classes')
j=HelloWorld;
end
The above function java_test() uses the Java class 'HelloWorld' which is located in the 'C:\classes' folder specified by the 'javaaddpath('C:\classes')' command. Now, if the above function is compiled and deployed on a target machine, make sure that the Java class file 'HelloWorld.class' has the same path (C:\classes) on the target machine.
Note that it might not be possible for the user on the target machine to have sufficient rights to create folders to match the absolute path of the class files on the development machine and in such cases using a relative path is better suited. The following example demonstrates the how the relative path can be used with the JAVAADDPATH command:
function java_test()
javaaddpath('.\')
j=HelloWorld;
end
In this case, instead of specifying an absolute path for the Java class file, it is specified as relative to the current directory using the 'javaaddpath('.\')' command. Note that this requires the Java class file to be present in the current working directory for both the development as well as the target machines. In this case, make sure that you include the class files along with the .EXE and the .CTF files in your distribution and advise the user of the stand-alone application to place the class files in the same directory as the .EXE and the .CTF files.
0 Comments
More Answers (0)
See Also
See Also
Categories
Find more on Java Package Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!