Hi All,

I'm running through "Head First Java" and I'm hitting a snag with an exercise involving RMI.

My Classes ----

package myremoteimpl;

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

/**
 *
 * @author Michael
 */
public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote {

    public String sayHello() {
        return "Server says, 'Hey'";
    }

    public MyRemoteImpl() throws RemoteException {}

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            MyRemote service = new MyRemoteImpl();
            Naming.rebind("RemoteHello", service);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}

----

package myremoteclient;

import java.rmi.*;

/**
 *
 * @author Michael
 */
public class MyRemoteClient {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new MyRemoteClient().go();
    }

    public void go() {
        try {
            //System.setSecurityManager(new SecurityManager());
            MyRemote service = (MyRemote) Naming.lookup("rmi://127.0.0.1/RemoteHello");

            String s = service.sayHello();

            System.out.println(s);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}

----

The interface is shared by both -- one in each respective package (with the correct package name for each of course - I'm only showing one here)

package myremoteimpl;

import java.rmi.*;

/**
 *
 * @author Michael
 */
public interface MyRemote extends Remote {

    public String sayHello() throws RemoteException;
}

So once I had these I went to the command line and ran within the generated "classes" folder for "MyRemoteImpl":

rmic myremoteimpl.MyRemoteImpl

This generated the stub (no skeleton...because I am using a version beyond 1.2? 1.5? ... something like that, from what I understand -- I'm using jdk1.7.0_51)

I copied the stub into the "classes" folder for "MyRemoteClient".

Then, from the "classes" folder for "MyRemoteImpl" I ran rmiregistry in the command line.

I then started the MyRemoteImpl app ---- everything fine so far --- it runs, no errors.

I then started the MyRemoteClient app and got the following error (running it from NetBeans):

run:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
    java.lang.ClassNotFoundException: myremoteimpl.MyRemoteImpl_Stub (no security manager: RMI class loader disabled)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Naming.java:101)
    at myremoteclient.MyRemoteClient.go(MyRemoteClient.java:27)
    at myremoteclient.MyRemoteClient.main(MyRemoteClient.java:21)
Caused by: java.lang.ClassNotFoundException: myremoteimpl.MyRemoteImpl_Stub (no security manager: RMI class loader disabled)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:393)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:185)
    at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:637)
    at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:264)
    at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:214)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1612)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
    ... 4 more
BUILD SUCCESSFUL (total time: 0 seconds)

Now from what I gather, there may be something I need to change within the java.policy in jre7/security once I remove the "comment out" from System.setSecurityManager(new SecurityManager()); (I'm not sure what), because at the moment, when I have that line in, I get a different error:

run:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
    at java.security.AccessController.checkPermission(AccessController.java:559)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
    at java.net.Socket.connect(Socket.java:574)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:208)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:147)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:341)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Naming.java:101)
    at myremoteclient.MyRemoteClient.go(MyRemoteClient.java:27)
    at myremoteclient.MyRemoteClient.main(MyRemoteClient.java:21)
BUILD SUCCESSFUL (total time: 0 seconds)

That's as far as I can get with this so any feedback from the forums would be most welcome.

Thanks

Forget rmic and stubs. They have been obsolete for years. For current tutorial info and a working sample this is a good source of info.

Thanks James. That saves me a headache, not to mention precious time :). I'll give that a gander.

This question has already been answered. Start a new discussion instead.