?
Solved

Basic RMI Trouble

Posted on 2002-06-10
22
Medium Priority
?
414 Views
Last Modified: 2013-12-29
Hi all,

I have just started using RMI and am having a problem as follows :-

I have created my classes in a package named rmitest.  The server class is a simple class called HelloWorld and I have succesfully created and compiled the HelloWorldImpl class.  The class HelloWorldImpl_Stub has been created and is in the same directory as HelloWorldImpl but when I try and start the main class that calls Naming.rebind(), i get a no class def found error.  

I have a directory called d:\JavaProjects\rmitest  the files in here are in a package called rmitest.  The files created by rmic are also in this directory. I invoked

rmic -d d:\JavaProjects -classpath d:\JavaProjects rmitest.HelloWorldImpl

This creates the HelloWorldImpl_Stub class and the HelloWorldImpl_Skel.class an puts them in d:\JavaProjects\rmitest

Then I start the registry tool.

Now when I try to invoke the main class (I called it RMIServer) by using
java -classpath d:\JavaProjects rmitest.RMIServer

I get a NoClassDefFound error, complaining it can't find rmitest.HelloWorldImpl_Stub.  When I change the name of the main class parameter(to rmitest.HelloWorldImpl_Stub) to the VM, it finds it OK but complains of no main method as I would expect.  So that proves the class is there and in the right package.


Any ideas ?

Cheers
Steve.
0
Comment
Question by:StevenWood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 11
22 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 7066852
 Well, everything seems fine from your description.


  Have you tried to be in the d:\JavaProjects\rmitest folder and do a:

java -classpath . RMIServer

  and see what happens? Could it also be that there is one mor folder within the rmitest (so you get a tree like: d:\JavaProject\rmitest\rmitest)?

  Hope it helps.
0
 

Author Comment

by:StevenWood
ID: 7066887
No, there is no extra folder within rmitest.  Also I tried using JBuilder to show the methods and package declaration for a .class file and it shows that both the classes created by rmic are in the package rmitest.

Thanks anyway
0
 
LVL 35

Expert Comment

by:girionis
ID: 7066900
 Have you tried to run the class from within the d:\JavaProjects\rmitest folder and see what happens?
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:StevenWood
ID: 7066915
yep, i tried that too.  it doesn't work at all because the class name is rmitest.RMIServer so if I try

d:\javaprojects\rmitest> java RMIServer

this is noclassdeffound because the class is called rmitest.RMIServer

and

d:\JavaProjects\rmitest> java rmitest.RMIServer

fails also because VM looks for a folder called rmitest inside rmitest i.e. d:\JavaProjects\rmitest\rmitest
0
 
LVL 35

Expert Comment

by:girionis
ID: 7066930
 Sorry, I have run out of ideas. Can you post your code here so I can compile it and try it as well?

0
 

Author Comment

by:StevenWood
ID: 7066949
yep, i tried that too.  it doesn't work at all because the class name is rmitest.RMIServer so if I try

d:\javaprojects\rmitest> java RMIServer

this is noclassdeffound because the class is called rmitest.RMIServer

and

d:\JavaProjects\rmitest> java rmitest.RMIServer

fails also because VM looks for a folder called rmitest inside rmitest i.e. d:\JavaProjects\rmitest\rmitest
0
 

Author Comment

by:StevenWood
ID: 7066959
OK, are you running on windows ?  I'm using windows NT 4.

Here are the files (as you can see they are very simple :-
i use ------- to separate each file.

------------------------------------------------------

package rmitest;

import java.rmi.*;

public interface HelloWorld extends Remote
{

  public String getMessage() throws RemoteException;

}

----------------------------------------------------------


package rmitest;

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.Naming;

public class HelloWorldImpl extends UnicastRemoteObject implements HelloWorld
{

  public HelloWorldImpl()
  throws RemoteException
  {
  }

  public String getMessage()
  throws RemoteException
  {
    return "Hello World.";
  }

}


--------------------------------------------------------

package rmitest;

import java.rmi.Naming;


public class RMIServer
{

  public static void main(String[] args)
  throws Exception
  {
    HelloWorldImpl hello = new HelloWorldImpl();
    Naming.rebind("hello", hello);
  }

}

----------------------------------------------------------

package rmitest;

import java.rmi.Naming;

public class RMIClient
{

  public static void main(String[] args)
  throws Exception
  {

    HelloWorld hello = (HelloWorld) Naming.lookup("rmi://localhost//hello");
    System.out.println(hello.getMessage());

  }

}

--------------------------------------------------------



The order i did things was
1) Compile classes using javac
2) compile rmitest.HelloWorldImpl using rmic
3) start rmiregistry
4) try and run the program RMIServer

Thanks
Steve.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7067007
 Well it works on my machine... I am getting of course the ConnectException but this is because I am not running the rmiregistry. The steps I followed:

  1) created a folder called java (c:\java)
  2) Copied all your files in there (c:\java\HelloWorldImpl.java etc)
  3) Compiled everything using: javac -d . *.java
  This created a folder called rmitest within the java folder that contans all the class files (c:\java\rmitest\HelloWorldImpl.class etc).
  4) Used rmic to create stubs and skeletons: rmic -d . -classpath . rmitest.HelloWorldImpl
  5) Ran it using: java -classpath . rmitest.RMIServer

  Hope it helps. Maybe you should have used the "." (current directory) instead of setting it usind d:\JavaProjects

  Hope it helps.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7067012
 By the way I am using Windows NT as well.
0
 

Author Comment

by:StevenWood
ID: 7067015
OK, are you running on windows ?  I'm using windows NT 4.

Here are the files (as you can see they are very simple :-
i use ------- to separate each file.

------------------------------------------------------

package rmitest;

import java.rmi.*;

public interface HelloWorld extends Remote
{

  public String getMessage() throws RemoteException;

}

----------------------------------------------------------


package rmitest;

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.Naming;

public class HelloWorldImpl extends UnicastRemoteObject implements HelloWorld
{

  public HelloWorldImpl()
  throws RemoteException
  {
  }

  public String getMessage()
  throws RemoteException
  {
    return "Hello World.";
  }

}


--------------------------------------------------------

package rmitest;

import java.rmi.Naming;


public class RMIServer
{

  public static void main(String[] args)
  throws Exception
  {
    HelloWorldImpl hello = new HelloWorldImpl();
    Naming.rebind("hello", hello);
  }

}

----------------------------------------------------------

package rmitest;

import java.rmi.Naming;

public class RMIClient
{

  public static void main(String[] args)
  throws Exception
  {

    HelloWorld hello = (HelloWorld) Naming.lookup("rmi://localhost//hello");
    System.out.println(hello.getMessage());

  }

}

--------------------------------------------------------



The order i did things was
1) Compile classes using javac
2) compile rmitest.HelloWorldImpl using rmic
3) start rmiregistry
4) try and run the program RMIServer

Thanks
Steve.
0
 

Author Comment

by:StevenWood
ID: 7067040
OK this helps, its still not working but when I dont start the rmiregistry, i get the same error as you.  ConnectionRefused

When I start the rmiregistry, i get the NoClassDefFoundError still.  Why can't you start the rmiregistry tool ?
0
 
LVL 35

Expert Comment

by:girionis
ID: 7067116
 Then you probably need to set the system property to download the stub classes dynamicaly to the registry and then you can try running the client again...
  http://java.sun.com/products/jdk/1.1/docs/guide/rmi/getstart.doc.html#5522

  I will try it as well and let you know what happened.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7067266
 Ok I have tried it properly. It works fine...

  start the rmiregistry with: start rmiregistry and then run the server using: java -classpath . -Djava.rmi.server.codebase=http://locahost/java/ rmitest.RMIServer (you will need to substitute "java" with your "JavaProject")

  Then run the client with java -classpath . rmitest.RMIClient and you will get the messages:

 Starting hello...
 Hello World.

  By the way you will need to chaneg the: Naming.lookup("rmi://localhost//hello"); (in your client file) to Naming.lookup("rmi://localhost/hello");

  Hope it helps.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7067290
 Well I have just tried it without setting the rmi codebase system property and works as well.

  1) start rmiregistry
  2) java -classpath . rmitest.RMIServer
  3) java -classpath . rmitest.RMIClient

  Hope it helps.
0
 

Author Comment

by:StevenWood
ID: 7072617
argh ! I still can't get it to work.  Any other ideas ?  You can get the points anyway, thanks for your help.

Steve.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7072633
 Are you still getting the same error message?
0
 

Author Comment

by:StevenWood
ID: 7072640
yip, the same ClassNotFoundException.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7072646
 Weird... I have just tried it again and it works fine... I can see the "Hello World" message on the screen when I start the client... have you taken out the second "/" from the "rmi://localhost//hello" string so it looks like: "rmi://localhost/hello"?
0
 

Author Comment

by:StevenWood
ID: 7072651
Here is the actual error trace :-    

   java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
        java.lang.ClassNotFoundException: rmitest.HelloWorldImpl_Stub
        at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
n Source)
        at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
        at sun.rmi.server.UnicastRef.invoke(Unknown Source)
        at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
        at java.rmi.Naming.rebind(Unknown Source)
        at rmitest.RMIServer.main(RMIServer.java:14)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested ex
ception is:
        java.lang.ClassNotFoundException: rmitest.HelloWorldImpl_Stub
        ... 6 more
Caused by: java.lang.ClassNotFoundException: rmitest.HelloWorldImpl_Stub
        ... 6 more
0
 

Author Comment

by:StevenWood
ID: 7072656
I dont even get to run my RMIClient because the RMIServer wont start thats where the exception is thrown.
0
 

Author Comment

by:StevenWood
ID: 7072707
IT WORKS!!!!!

I got it to work by invoking rmiregistry from d:\JavaProjects rmiregistry must look there for classes.  I looked at the doc for rmiregistry and i dont know how you specify a classpath.  I was invoking it from jdk1.4\bin

ah well....

Thanks anyway
0
 
LVL 35

Accepted Solution

by:
girionis earned 400 total points
ID: 7072724
 I see.... I was invoking it from the folder where my java source files are as well (c:\java) while my classes are in the c:\java\rmitest. This is whay I had -classpath . and it was looking in the current folder.

  Finally :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question