Java Reference
In-Depth Information
file: URL. The client must read the remote stub classes from that URL, and
a suitable permission to read that location must be granted in the client's policy
file. Therefore, the client's policy file must read as follows:
grant {
permission java.net.SocketPermission " localhost " , " connect,
resolve " ;
permission java.io.FilePermission
" c: \\ javatech \\ rmi18 \\ build \\ classes \\ - " , " read " ;
}
The syntax of the read permission shown is for a Windows machine. The path
specified must be an absolute path and must correspond to the absolute path
specified in the file: URL given as the server's codebase. The use of the
double “\\ characters is required on Windows. For an RMI client running on
a Unix box, the file might read as follows
grant {
permission java.net.SocketPermission " localhost " , " connect,
resolve " ;
permission java.io.FilePermission
" /javatech/rmi18/build/classes/- " , " read " ;
}
In both cases, notice the use of the - at the end of the directory specification
which indicates the named directory and all directories below it. For more details
of the policy file syntax, see the Java SDK documentation.
An alternative to using the file permission when client and server are on the
same machine is to arrange the client's CLASSPATH to point to where all the
class files, including the remote stubs, reside. Since the default policy file always
permits reading the CLASSPATH ,nospecial file permission is needed. However,
doing so would not test or demonstrate the downloadable bytecodes feature of
RMI. Therefore, we use a client-side JAR file that includes only the minimum
classes needed to start the client, specifically avoiding the remote stub class files
when we create the JAR file. Then we set the server's codebase to include the
location of the remote stubs and use the file permission shown above.
18.6 Finally, a working example
We finally have all the pieces in place to run a real, but simple, example RMI
client/server application with the restriction that both client and server must be
on the same machine. We make minor modifications in the next section to permit
the use of a remote machine. For completeness, the entire code is shown here,
including full package statements and exception handling which were omitted
Search WWH ::




Custom Search