javaclasspath

Return Java class path or specify dynamic path

Syntax

  • javaclasspath
  • javaclasspath('-dynamic') example
  • javaclasspath('-static')
  • dpath = javaclasspath example
  • spath = javaclasspath('-static')
  • jpath = javaclasspath('-all')
  • javaclasspath(dpath) example
  • javaclasspath(dpath1,dpath2)

Description

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

example

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

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

example

dpath = javaclasspath returns the dynamic path, dpath.

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.

example

javaclasspath(dpath) changes the dynamic path to dpath. Use this syntax to reload Java classes.

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

example

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

Examples

expand all

Modify Path Using Cell Array

Create a cell array with two path values.

dpath = {'http://domain.com','http://some.domain.com/jarfile.jar'};

Set message flag to display class-loading messages.

javaclasspath('-v1')

Modify path.

javaclasspath(dpath)
Loading following class path(s) from local file system:
* http://domain.com
* http://some.domain.com/jarfile.jar

Display updated dynamic path.

javaclasspath('-dynamic')
		DYNAMIC JAVA PATH

	http://domain.com                 
	http://some.domain.com/jarfile.jar

MATLAB® adds folders from dpath to the existing path.

Capture Contents of Dynamic Path

Create a cell array, p, with the entries of the dynamic path.

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

     {}

If there are no entries on the dynamic path, MATLAB creates an empty cell array.

Input Arguments

expand all

dpath — Path entriesstring | cell array of strings

Path entries, specified as a string or cell array of strings, to specify for the dynamic path. Converts relative paths to absolute paths.

Example: javaclasspath('http://domain.com')

Data Types: char | cell

dpath1,dpath2 — Path entriesstring | cell array of strings

Path entries, specified as a string or cell array of strings, concatenated, to specify for the dynamic path.

Data Types: char | cell

statusmsg — Message flag'-v0' (default) | '-v1'

Message flag, specified as one of these values:

'-v0'

Does not display status messages while loading the Java path from the file system.

'-v1'

Displays status messages.

Controls status message display from the javaclasspath, javaaddpath, and javarmpath functions.

Output Arguments

expand all

dpath — Dynamic path entriescell array of strings

Dynamic path entries for the current path, returned as a cell array of strings. If no path entries are defined, dpath is an empty cell array.

spath — Static path entriescell array of strings

Static path entries for the current path, returned as a cell array of strings. If no path entries are defined, spath is an empty cell array.

jpath — All path entriescell array of strings

All path entries, returned as a cell array of strings. If no path entries are defined, jpath is an empty cell array.

More About

expand all

Static Path

The static path is a segment of the Java path which is loaded at the start of each MATLAB session from the MATLAB built-in Java path and the file javaclasspath.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 javaclasspath.txt and restart MATLAB. For more information, see The Static Path.

Dynamic Path

The dynamic path is a segment of the Java path which is loaded 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. For more information, see The Dynamic Path.

Tips

  • MATLAB searches the static path before the dynamic path.

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

  • MATLAB calls the clear java command whenever you change the dynamic path. This command clears the definitions of all Java classes defined by files on the dynamic class path, removes all global variables and variables from the base workspace, and removes all compiled scripts, functions, and MEX-functions from memory.

  • MATLAB displays a warning if you add an entry to the dynamic path that is already specified on the static path.

Was this topic helpful?