Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Unable to bind class to RMI registry

Thread view: 
Robin - 24 Apr 2006 17:07 GMT
I'm not sure I understand the exceptions being thrown here.  I need a
connection between two servers and I chose to use RMI.  Whenever I try
to run the code that starts the "RMI Server" I am getting an exception.
I will post the code, and then the exceptions.  Hopefully someone can
see an error - I cannot.

Interface:

public interface G2RemoteInterface extends Remote {
   public InquiryConfig getConfig(String configFile) throws
RemoteException;
   public Response makeRequest(G2Request request) throws
RemoteException;
}

Implementation:

public class G2Remote implements G2RemoteInterface, Serializable {
    private static final long serialVersionUID = 2530016775139934837L;

    public G2Remote() throws RemoteException {
        System.out.println("G2Remote Object Constructed");
    }

    public InquiryConfig getConfig(String configFile) throws
RemoteException {
        InquiryConfig config = new InquiryConfig();
        try {
            config.load(configFile);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return config;
    }

    public Response makeRequest(G2Request request) throws RemoteException
{
        try {
            return request.runDataHandler();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Server to launch this:

public class G2RemoteServer {

    public static void main(String[] args) {
        try {
            //System.out.println("feh");
            Naming.rebind("G2Remote", new G2Remote());
            System.out.println("G2 Remote Server running...");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

I do have rmiregistry running before the server is ever called.  When I
do run it, I get this error:

G2Remote Object Constructed
java.rmi.ServerException: RemoteException occurred in server thread;
nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested
exception is:
    java.lang.ClassNotFoundException:
tpc.circulation.discus.g2.remote.G2Remote
    at
sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:385)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
    at sun.rmi.transport.Transport$1.run(Transport.java:153)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
    at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:595)
    at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown
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
tpc.circulation.discus.g2.remote.G2RemoteServer.main(G2RemoteServer.java:26)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments;
nested exception is:
    java.lang.ClassNotFoundException:
tpc.circulation.discus.g2.remote.G2Remote
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at
sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:375)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
    at sun.rmi.transport.Transport$1.run(Transport.java:153)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
    at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.ClassNotFoundException:
tpc.circulation.discus.g2.remote.G2Remote
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:242)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:430)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
    at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
    at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
    at
sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
    at
java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1538)
    at
java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
    at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
    ... 9 more

I hope someone can help.

Cheers,

Robin
Jeroen V. - 24 Apr 2006 17:52 GMT
You should generate stubs (using rmic) & deploy them with your application.
Robin - 24 Apr 2006 17:56 GMT
I should have mentioned that I was building the Stub's and Skel's.
Interesting -- when I build via an ANT script I only get the stub, but
if I do an rmic on the command line I'm getting both Stub's and Skel's.

Robin
Robin - 24 Apr 2006 19:35 GMT
If anyone is reading this thread - I found the reason for my error.

I was starting rmiregistry in one terminal window, while launching the
server in another.  When launching the server I used a -classpath
option for my java command.

The problem was that my CLASSPATH env variable was not set correctly
when I was starting rmiregistry.  Even though I'm not relying on it for
running the server, it must be there for the registry.

This worked:
$ CLASSPATH=/path/to/jars ; export CLASSPATH
$ rmiregistry &
$ java -cp $CLASSPATH the.rmi.server.ClassName

Robin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.