|
|
Step 6: compiling and running the test client
e're now ready to run the test client, but first a word
of explanation.
In reality the client and the server are likely to be on different computers.
When you compile the client, the compiler needs to know about the
organization and methods of classes in the Bean so it can do type checking.
When you run the client, the run-time engine needs to know about the Bean
classes, because type-casting is done at run-time. So when the client attempts
to cast the remote reference to a reference to an object of class
InterestHome for example, it needs to know about this class. This
means that you will need the Bean class files on both the client and the server
even though they execute on the server. This is fairly obvious if you think
about the logic, but it causes all sorts of problems for people who are new to
RMI programming. If the client can't find the Bean classes, you will get error
messages like this:
javax.naming.CommunicationException [Root exception is
java.lang.ClassNotFoundException: com.web_tomorrow.interest.InterestHome]
A `communication exception' is the exception that represents any error that
can't readily be ascribed to a definite cause. If you get this message you need
to pay attention to the CLASSPATH on the client.
If the client program is at the top of the directory hierarchy, with the Bean
classes below it, then we can run it like this:
java -classpath $$CLASSPATH:\
/usr/lib/jboss/lib/ext/ejb.jar:/usr/lib/jboss/client/jboss-client.jar \
InterestClient
Once again, this needs to go in a shell script or a Makefile; you won't want to
type it more than once.
Note the long CLASSPATH; it needs to include the jBoss client classes and the
EJB classes as well as the standard classpath (if any).
If all is well, the test client produces the following output:
Got context
Got reference
Interest on 1000 units, at 10% per period, compounded over 2 periods is:
210.00000000000023
The Bean should produce an output on the server as well; this is to show that
the Bean has executed on the server, not the client. Look for something like
this in the server log:
[Interest] Someone called `calculateCompoundInterest!'
Well, that's it. We covered coding, compiling and deploying the Bean, and
coding and running a simple test client. If you found this article useful, drop
me a line at k.boone@web-tomorrow.com; if there's
enough response I may be persuaded to produce some more sophisticated tutorials.
Kevin Boone, June 2000
|