Need help getting this simple Java RMI program running

I've been pulling my hair out trying to get RMI running on windows.  I decided to do a verbatim copy of a tutorial to see if it would work, well it didn't.  Here is the sample code:

//HelloInterface.java - located in dir c:\java
//
import java.rmi.*;

public interface HelloInterface extends Remote {

  public String say() throws RemoteException;
}

//Hello.java - located in c:\java
//
import java.rmi.*;
import java.rmi.server.*;

public class Hello extends UnicastRemoteObject implements HelloInterface {
  private String message;

  public Hello (String msg) throws RemoteException {
    message = msg;
  }

  public String say() throws RemoteException {
    return message;
  }
}


//HelloServer.java - located in c:\java
import java.rmi.*;
import java.rmi.Naming;

public class HelloServer{

  public static void main (String[] argv) {
    try {
      Naming.rebind ("Hello", new Hello ("Hello, world!"));
      System.out.println ("Hello Server is ready.");
    } catch (Exception e) {
      System.out.println ("Hello Server failed: " + e);
    }
  }

}



Then I open a command prompt and go to c:\java and type:
C:\java>javac HelloInterface.java
C:\java>javac Hello.java
C:\java>rmic Hello
C:\java>javac HelloServer.java

I then open a second command prompt and navigate to c:\registry to (to avoid being in the same directory as the stub files) and type:
C:\register>C:\j2sdk1.4.2_03\bin\rmiregistry

In the original command prompt, I then run HelloServer.  I've tried running it a 100 different ways and always get the same error:
Hello Server failed: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
        java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
        java.lang.ClassNotFoundException: Hello_Stub

I've tried just running it as:
java HelloServer
java -classpath . HelloServer

C:\java>java -Djava.rmi.server.codebase=http://localhost -classpath . HelloServer

C:\java>java -Djava.security.policy=..\policy.all -Djava.rmi.server.codebase=http://localhost -classpath . HelloServer

Where policy.all is:
grant {
      permission java.security.AllPermission;
};


And pretty much just about every combination of the above that you can think of.

JDmears2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

b3lzCommented:
       java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
        java.lang.ClassNotFoundException: Hello_Stub

^^ there is something wrong with your stub/skeleton, be sure to first create them before trying to use them. If you don't first make the stubs and skeletons, you will get that ClassNotFoundException. Most IDE's will make them for you.

The nested marshalling exception is because the stubs/skeleton are needed to translate your objects etc to something that can be transferred over the wire. You created the hello with rmic, but be sure to make them both of server and client.

More info on rmic you can find here:

http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/rmic.html

Good luck,

greetings, belz.
0
kiranhkCommented:
your code should be

public class HelloServer{

  public static void main (String[] argv) {
    try {
      Naming.rebind ("//localhost/HelloServer", new Hello ("Hello, world!"));
      System.out.println ("Hello Server is ready.");
    } catch (Exception e) {
      System.out.println ("Hello Server failed: " + e);
    }
  }

}

http://java.sun.com/j2se/1.3/docs/guide/rmi/getstart.doc.html#5912

http://java.sun.com/j2se/1.3/docs/guide/rmi/getstart.doc.html
0
JDmears2Author Commented:
b3lz:  Well, I'm not trying to get a client working yet, because it wouldn't do much good if the server isn't working.    The stub and skeleton files are in the same directory as HelloServer.java

kiranhk:  I tried changing the first argumnet to Naming.rebind as you suggested, but I received the same error message.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

JDmears2Author Commented:
I also just tried adding:

            if (System.getSecurityManager() == null) {
                System.setSecurityManager(new RMISecurityManager());
            }

As the first lines to the main method in HelloServer and if I try to run it after recompiling without the policy file, I get an AccessControlException.  If I then try to also include the policy file, I get the same error as before.
0
kiranhkCommented:
ok, assuming that you are in the same folder as your generated Stubs

then try this

rmic -classpath . Hello
0
objectsCommented:
try:

java -Djava.rmi.server.codebase=file:///java/ HelloServer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JDmears2Author Commented:
What objects posted was almost the ticket.  I still needed to add the security policy though.  Any reason why I need these two switches when all the examples online are able to just type java HelloServer and be on their marry way?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.