Static Path of Java Class Path
The static path is loaded at the start of each MATLAB® session from the MATLAB built-in Java® path and the
javaclasspath.txt file. The static path offers
better Java class-loading performance than the dynamic Java path. However, if you modify the static path, you must restart MATLAB.
To add files to the static Java class path, create a
javaclasspath.txt file. For
instructions, see Create javaclasspath.txt File.
For convenience when developing your own Java classes, add entries to the dynamic Java class path. For information, see Dynamic Path of Java Class Path.
For more information about how MATLAB uses the class path, see Java Class Path.
Each line in the
javaclasspath.txt file contains a reference to a
Java class folder or JAR file. To create the file:
Create an ASCII text file named
Enter the name of a Java class folder or JAR file, one per line. The format of the name depends on how the class is defined.
Simplify folder specifications in cross-platform environments by using the
Save the file in your preferences folder. To view the location of the preferences folder, type:
Alternatively, save the
javaclasspath.txtfile in your MATLAB startup folder. To identify the startup folder, type
pwdat the command line immediately after starting MATLAB. Classes specified in the
javaclasspath.txtfile in the startup folder appear on the path before classes specified in the file in the preferences folder. If a class appears in more than one folder or jar file, then Java uses the first one it finds.
MATLAB reads the static class path only at startup. If you edit
javaclasspath.txt or change your
.class files while
MATLAB is running, then restart MATLAB to put those changes into effect.
If you do not want MATLAB to use the entries in the
javaclasspath.txt file, then
start MATLAB with the
Add Individual (Unpackaged) Classes
To make individual classes—classes that are not part of a
package—available in MATLAB, specify the full path to the folder containing the
files. For example, for a compiled Java class in the file
c:\work\javaclasses\test.class, add the
following entry to the
To make a package available to MATLAB, specify the full path to the parent folder of the highest level
folder of the package path. This folder is the first component in the package
name. For example, if your Java class package
com.mw.tbx.ini has its classes in folder
c:\work\com\mw\tbx\ini, add the following entry to the
Add JAR File Classes
A JAR file contains multiple Java classes and packages in a compressed ZIP format. For information on the jar (Java Archive) tool and JAR files, consult your Java development documentation.
To make the contents of a JAR file available for use in MATLAB, specify the full path, including the full file name, for the JAR file. You also can put the JAR file on the MATLAB path.
The path requirement for JAR files is different from the requirement for
.class files and packages, for which you do not specify file
For example, you have a JAR file named
mylibrary.jar in the
C:\Documents\MATLAB\, containing a method,
cd(prefdir) edit javaclasspath.txt
Add the following text on a new line in the file.
Save and close the file.