Java Reference
In-Depth Information
controlling the applet will have already installed a security manager. Therefore
it's a good idea to include the if-test shown above to check for the presence of an
existing security manager before installing another one.
18.5.2 The codebase
A concept related to the security manager is the codebase . The java.rmi.
server.codebase property is specified when the server starts up and identifies
where downloadable bytecodes may be found. The RMI codebase is closely
related to an applet codebase, and both are similar to a CLASSPATH . The codebase
specifies a source from which a remote JVM can load needed classes that cannot
be found in the local CLASSPATH . When a local JVM is running and loading
classes from a local disk-based source, it searches for classes within the list of
locations specified in the CLASSPATH . When a remote client's JVM needs to
obtain RMI stub classes, it looks first in the local CLASSPATH and then in the
list of locations specified by the codebase.
Note that the codebase is used by the client, but it is specified on the server.
When the RMI server registers itself with the registry, the codebase is “remem-
bered” by the registry. In fact, the registry itself uses the server's codebase to find
the remote object's stub class during registration. (For this reason, the registry
should not be started with a CLASSPATH that includes the remote object's stubs.)
If the codebase is not properly specified - i.e. if the registry cannot find the needed
stub classes in the location specified by the codebase - then an exception is thrown
when the server attempts to bind() or rebind() itself into the registry. The
exception is a RemoteException nesting an UnmarshalException nest-
ing a ClassNotFoundException . This chain of exceptions is a common error
and is almost always the result of a bad codebase value.
The codebase is a URL or a space-delimited list of URL locations where the
needed stub classes, as well as any other classes needed by the stubs, can be found.
These URLs must be absolute paths, not relative paths. When running both client
and server on the same machine, they may be file: URLs, though it is more
common to use http: URLs. The URL may point to a directory location
or a JAR file. If a directory, it is important that the URL end in a trailing /
character. If the downloadable bytecodes are supplied by an http: URL, then
there must be an http server running on the specified host that can serve those
bytecodes.
The codebase property can be set using the -D syntax on the command line
when the server is started. An example is
-Djava.rmi.server.codebase = file:///rmiservers/example1/classes/
Since it is a “file:” URL, this codebase is suitable for when the client will be run-
ning on the same machine as the server. The URL specifies an absolute path to a
directory named /rmiservers/example1/classes. The needed class files
Search WWH ::




Custom Search