External Interfaces/API |
Making Java Classes Available to MATLAB
To make your third-party and user-defined Java classes available in MATLAB, place them on your MATLAB path by adding their locations to the file classpath
.txt. For more information on classpath.txt
, see Finding and Editing classpath.txt.
Making Individual (Unpackaged) Classes Available
To make individual classes (classes not part of a package) available in MATLAB, add to classpath.txt
an entry containing the full path to the directory you want to use for the .class
file(s).
For example, to make available your compiled Java classes in the file d:\work\javaclasses\test.class
, add the following entry to your classpath.txt
file.
Making Entire Packages Available
To access one or more classes belonging to a package, you need to make the entire package available to MATLAB. Do this by adding to classpath.txt
the full path to the parent directory of the highest-level directory of the package path. This directory is the first component in the package name.
For example, if your Java class package com.mw.tbx.ini has
its classes in directory d:\work\com\mw\tbx\ini
, add the following entry to your classpath.txt.
Making Classes in a JAR File Available
You can use the jar
(Java Archive) tool to create a JAR file, containing multiple Java classes and packages in a compressed ZIP format. For information on jar
and JAR files, consult your Java development documentation or the JavaSoft web site. See also To Learn More About Java Programming.
To make the contents of a JAR file available for use in MATLAB, add to classpath.txt
the full path, including full filename, for the JAR file.
Note
Note that the classpath.txt requirement for JAR files is different than that for .class files and packages, for which you do not specify any filename.
|
For example, to make available the JAR file e:\java\classes\utilpkg.jar
, add the following to your classpath.txt
.
Finding and Editing classpath.txt
To make your Java classes available, you can edit the default classpath.txt
, which is in the directory toolbox/local
. Or, you can copy the default classpath.txt
from this directory to your own startup directory where the changes you make to it do not affect anyone else.
To find the classpath.txt
that is used by your MATLAB environment, use the MATLAB which
function.
To edit either the default file or the copy you have made in your own directory, enter the following command in MATLAB.
MATLAB reads classpath.txt
only upon startup. So, if you edit classpath.txt
or change your .class
files while MATLAB is running, you must restart MATLAB to put those changes into effect.
Bringing Java Classes into MATLAB | Loading Java Class Definitions |