| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
javaclasspath
javaclasspath('-dynamic')
javaclasspath('-static')
dpath = javaclasspath
spath = javaclasspath('-static')
jpath = javaclasspath('-all')
javaclasspath(dpath)
javaclasspath(dpath1, dpath2)
javaclasspath(statusmsg)
javaclasspath displays the static and dynamic segments of the Java path. (See the Remarks section, below, for a description of static and dynamic Java paths.)
javaclasspath('-dynamic') displays the dynamic Java path.
javaclasspath('-static') displays the static Java path.
dpath = javaclasspath returns the dynamic segment of the Java path in cell array, dpath. If no dynamic paths are defined, javaclasspath returns an empty cell array.
spath = javaclasspath('-static') returns the static segment of the Java path in cell array, spath. No path information is displayed unless you specify an output variable. If no static paths are defined, javaclasspath returns an empty cell array.
jpath = javaclasspath('-all') returns the entire Java path in cell array, jpath. The returned cell array contains first the static segment of the path, and then the dynamic segment. No path information is displayed unless you specify an output variable. If no dynamic paths are defined, javaclasspath returns an empty cell array.
javaclasspath(dpath) changes the dynamic Java path to dpath, where dpath can be a string or cell array of strings representing path entries. Relative paths are converted to absolute paths. Uses the clear java command to refresh the classes defined on the dynamic Java path.
javaclasspath(dpath1, dpath2) changes the dynamic Java path to the concatenation of the two paths dpath1 and dpath2, where dpath1 and dpath2 can be a string or cell array of strings representing path entries. Relative paths are converted to absolute paths. Uses the clear java command to refresh the classes defined on the dynamic Java path.
javaclasspath(statusmsg) enables or disables the display of status messages from the javaclasspath, javaaddpath, and javarmpath functions. Values for the statusmsg argument are shown in the following table:
statusmsg | Description |
|---|---|
'-v1' | Display status messages while loading the Java path from the file system. |
'-v0' | Do not display status messages. This is the default. |
The Java path consists of two segments: a static path (read only at startup) and a dynamic path. The MATLAB software always searches the static path (defined in classpath.txt) before the dynamic path. Java classes on the static path should not have dependencies on classes on the dynamic path. Use javaclasspath to see the current static and dynamic Java paths.
MATLAB calls the clear java command whenever you change the dynamic path.
Path Type | Description |
|---|---|
Static | Loaded at the start of each MATLAB session from the file classpath.txt. The static Java path offers better Java class loading performance than the dynamic Java path. However, to modify the static Java path you need to edit the file classpath.txt and restart MATLAB. |
Dynamic | Loaded at any time during a MATLAB session using the javaclasspath function. You can define the dynamic path (using javaclasspath), modify the path (using javaaddpath and javarmpath), and refresh the Java class definitions for all classes on the dynamic path (using clear java) without restarting MATLAB. |
Create a function to set your initial dynamic Java class path:
function setdynpath
javaclasspath({
'C:\Work\Java\ClassFiles', ...
'C:\Work\JavaTest\curvefit.jar', ...
'C:\Work\JavaTest\timer.jar', ...
'C:\Work\JavaTest\patch.jar'});
% ----------- end of file ------------
Call this function to set up your dynamic class path. Then, use the javaclasspath function with no arguments to display all current static and dynamic paths:
setdynpath;
javaclasspath
STATIC JAVA PATH
D:\Sys0\Java\util.jar
D:\Sys0\Java\widgets.jar
D:\Sys0\Java\beans.jar
.
.
DYNAMIC JAVA PATH
C:\Work\Java\ClassFiles
C:\Work\JavaTest\curvefit.jar
C:\Work\JavaTest\timer.jar
C:\Work\JavaTest\patch.jar
At some later time, add the following two entries to the dynamic path. One entry specifies a directory and the other a Java Archive (JAR) file. When you add a directory to the path, The MATLAB software includes all files in that directory as part of the path:
javaaddpath({
'C:\Work\Java\Curvefit\Test', ...
'C:\Work\Java\mywidgets.jar'});
Use javaclasspath with just an output argument to return the dynamic path alone:
p = javaclasspath p = 'C:\Work\Java\ClassFiles' 'C:\Work\JavaTest\curvefit.jar' 'C:\Work\JavaTest\timer.jar' 'C:\Work\JavaTest\patch.jar' 'C:\Work\Java\Curvefit\Test' 'C:\Work\Java\mywidgets.jar'
Create an instance of the mywidgets class that is defined on the dynamic path:
h = mywidgets.calendar;
If, at some time, you modify one or more classes that are defined on the dynamic path, you will need to clear the former definition for those classes from MATLAB memory. You can clear all dynamic Java class definitions from memory using:
clear java
If you then create a new instance of one of these classes, MATLAB uses the latest definition of the class to create the object.
Use javarmpath to remove a file or directory from the current dynamic class path:
javarmpath('C:\Work\Java\mywidgets.jar');
javaaddpath, javarmpath, clear
![]() | javachk | javaMethod | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |