External Interfaces Reference Previous page   Next Page
javaclasspath

Set and get dynamic Java class path

Syntax

Description

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(dpath) sets the dynamic Java path to one or more directory or file specifications given in dpath, where dpath can be a string or cell array of strings.

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(statusmsg) enables or disables the display of status messages from the javaclasspath, javaaddpath, and javarmpath functions. Values for the statusmsg argument are

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.

Remarks

The Java path consists of two segments: a static path and a dynamic path. MATLAB always searches the static path before the dynamic path. Java classes on the static path should not have dependencies on classes on 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.

Examples

Create a function to set your initial dynamic Java class path:

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:

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, MATLAB includes all files in that directory as part of the path:

Use javaclasspath with just an output argument to return the dynamic path alone:

Create an instance of the mywidgets class that is defined on the dynamic path:

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,

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:

See Also

javaaddpath, javarmpath, clear


Previous page  javachk javaMethod Next page

© 1994-2005 The MathWorks, Inc.