Java Reference
In-Depth Information
leave off any -classpath specification when starting the registry. The RMI
registry is started, in Windows, with the rmiregistry command as follows:
start rmiregistry 3001
For Unix, we would use the command
rmiregistry 3001 &
In both cases, we've specified the port number 3001. If left off, the default RMI
port of 1099 is used. Since we've hard coded port 3001 in our source code, we
need to be sure to use port 3001 for the RMI registry. If there is already a process
using port 3001 on your machine, then you must choose a different unused port
number.
For some applications, it is possible and convenient to start the registry from
within the server program itself. Doing so saves the separate step of starting the
registry and keeps the registry port number and the server that uses the registry
at just one place in the code. We learn in Chapter 20 how to use that technique.
18.6.5 Start the server
We are finally ready to run the server. To do so, there are four things that
must be specified on the Java command line - the CLASSPATH , the code-
base, the policy file, and the name of the class to run. The CLASSPATH must
point to the build/classes directory. Alternatively, we could have created a
server.jar file containing all the classes in build/classes . The codebase
and policy files are specified as system properties using the -D syntax shown
earlier, and the class to run is the fully qualified RMIExampleServer class.
Therefore the command line to start the server is
java -classpath build/classes
-Djava.rmi.server.codebase = file:///c:/javatech-18/
build/classes/
-Djava.security.policy = local-server.policy
javatech.rmi18.server.impl.RMIExampleServer
Again, we've broken the command into multiple lines for appearance reasons.
On a Windows machine, this entire command must be entered on a single line.
Unix and Linux shells can use the line-continuation character. The policy file
specified, local-server.policy was shown earlier but is repeated here for
completeness:
grant {
permission java.net.SocketPermission " localhost " , " accept,
connect, resolve " ;
} ;
Search WWH ::




Custom Search