Main Content

javaclasspath

Return Java class path or specify dynamic path

Description

javaclasspath displays the static and dynamic segments of the Java® class path.

javaclasspath('-dynamic') displays the dynamic path.

javaclasspath('-static') displays the static path.

dpath = javaclasspath returns the dynamic path, dpath.

example

spath = javaclasspath('-static') returns the static path, spath.

jpath = javaclasspath('-all') returns the entire path, jpath. The returned cell array contains first the static segment of the path, and then the dynamic segment.

javaclasspath(dpath) changes the dynamic path to dpath. Use this syntax to reload Java classes that you are actively developing and debugging.

javaclasspath(dpath1,dpath2) changes the dynamic path to the concatenation of paths dpath1,dpath2.

javaclasspath(statusmsg) enables or disables the display of status messages.

Examples

collapse all

Create a cell array, p, with the entries of the dynamic path. If there are no entries on the dynamic path, then MATLAB® creates an empty cell array.

javaclasspath('-v0') % Suppress display of class-loading messages
p = javaclasspath
p = 

     {}

Input Arguments

collapse all

Path entries, specified as a string, an array of strings, a character vector, or a cell array of character vectors for the dynamic path. MATLAB converts relative paths to absolute paths.

Example: javaclasspath('https://www.example.com')

Data Types: char | cell

Path entries, specified as a string, an array of strings, a character vector, or a cell array of character vectors concatenated for the dynamic path.

Data Types: char | cell

Message flag, specified as one of these values.

'-v0'

Do not display status messages when loading the Java path from the file system.

'-v1'

Display status messages.

The statusmsg argument controls status message display from the javaclasspath, javaaddpath, and javarmpath functions.

Output Arguments

collapse all

Dynamic path entries for the current path, returned as an array of strings or a cell array of character vectors. If there are no path entries, then dpath is an empty cell array.

Static path entries for the current path, returned as an array of strings or a cell array of character vectors. If there are no path entries, then spath is an empty cell array.

All path entries, returned as an array of strings or a cell array of character vectors. If there are no path entries, then jpath is an empty cell array.

More About

collapse all

Static Path

The static path is a segment of the Java path that is loaded at the start of each MATLAB session from the MATLAB built-in Java path and the file javaclasspath.txt.

MATLAB searches the static path before the dynamic path.

The static Java path offers better Java class-loading performance than the dynamic Java path. To modify the static Java path, edit the file javaclasspath.txt and restart MATLAB. For more information, see Static Path of Java Class Path.

Dynamic Path

The dynamic path is a segment of the Java class path.

MATLAB provides the dynamic path as a convenience for when you develop your own Java classes. You can load the dynamic path any time during a MATLAB session using the javaclasspath function. Although the dynamic path offers flexibility in changing the path, Java classes on the dynamic path might load more slowly than classes on the static path. Also, classes on the dynamic path might not behave the same way as classes on the static path. If your class does not behave as expected, then use the static path. After you develop and debug a Java class, add the class to the static path.

  • To define the dynamic path, use javaclasspath.

  • To modify the path. use javaaddpath and javarmpath.

  • To refresh the Java class definitions for all classes on the dynamic path without restarting MATLAB, use clear java.

For more information, see Dynamic Path of Java Class Path.

Tips

  • Do not put Java classes on the static path that have dependencies on classes on the dynamic path. Such dependencies produce run-time errors.

  • To clear the definitions of all Java classes defined by files on the dynamic class path, call the clear command.

  • Adding an entry to the dynamic path when it is already specified on the static path produces a warning.

Version History

Introduced before R2006a