I am taking the first steps with RMI and I have a simple question.
I have a .jar file that has an implementation of several methods from the library. I want to call these methods in a .jar file using RMI.
I am trying to create a kind of shell to do this.
So, I am working on something like this:
Interface class This interface has methods that must be implemented by the remote object.
Implementation class . This class has an implementation of the interface methods, each implementation calls the corresponding method in the .jar file. For example, a jar file has a method called getDetails (), and returns a ResponseDetail object. ResponseDetail is the response class that I have in .jar.
Server class : it binds methods to rmiregistry
Client class : he will use the methods implemented in the implementation.
So far so good? :)
Now I have a lib folder where the .jar file is located.
On the server machine, I deployed the interface, implementation, and server classes. I created a stub and I successfully completed rmiregistry, but with these details:
To run rmiregistry, I had to set the classpath on the command line to link to .jar files, otherwise I get java.lang.NoClassDefFoundError. I did this with this .sh file:
THE_CLASSPATH= for i in `ls ./lib/*.jar` do THE_CLASSPATH=${THE_CLASSPATH}:${i} done rmiregistry -J-classpath -J".:${THE_CLASSPATH}"
To start the server, I had to set the class path to refer to .jar files, otherwise I get java.lang.NoClassDefFoundError. I used something like this:
THE_CLASSPATH= for i in `ls ./lib/*.jar` do THE_CLASSPATH=${THE_CLASSPATH}:${i} done java -classpath ".:${THE_CLASSPATH}" Server
Client machine: To run the Client.class file from the client computer, I had to copy the .jar files and refer to them in the class path, because otherwise it does not start, and I get java.lang.NoClassDefFoundError. I had to use this on the client machine:
THE_CLASSPATH= for i in `ls ./lib/*.jar` do THE_CLASSPATH=${THE_CLASSPATH}:${i} done java -classpath ".:${THE_CLASSPATH}" HelloClient
This is normal? I mean, do I need to copy .jar files to the client machine to execute methods via RMI?