客户段程序//remoteClient.java
//----------------
import java.net.*;
import java.rmi.*;public class remoteClient
{
  public static void main(String args[])
  {
    System.setSecurityManager(new java.rmi.RMISecurityManager());
    try
    {
      RemoteInterface server = (RemoteInterface)Naming.lookup("//202.121.76.17/ServerTest");
      String serverString = server.message("Hello There");
      System.out.println("The server says:"+serverString);
    }catch(Exception e)
    {System.out.println(e.toString());}
  }
}

解决方案 »

  1.   

    服务端执行了:
    javac remoteObject.java
    rmic remoteObject
    (生成了2个文件:remoteObject_Skel.class,remoteObject_Stub.class)
    start rmiregistry
    javaw -Djava.security.polic=xxx.policy remoteObject客户端执行了:
    java -Djava.security.polic=xxx.policy remoteClient报错:
    java.security.AccessControlException: access denied (java.net.SocketPermission 2
    02.121.76.17:1099 connect,resolve)
    ---------------------------------------
    客户段和服务端在同一台机器上是正常的。
    现在分开了在2台机器上就报错,怎么回事??(服务端的IP 202.121.76.17)
    ------------------------------------
    remoteObject_Skel.class
    remoteObject_Stub.class
    这2个文件到底在服务端生成还是在客户段生成???
      

  2.   

    应该是这样的:
    E:\RMI>java -Djava.security.policy=file:/c:/xxx.policy remoteClient
    注:客户机的c般根目录下放xxx.policy文件。
    给分吧。^_^
      

  3.   

    RemoteInterface server = (RemoteInterface)Naming.lookup("//202.121.76.17/ServerTest");
    最好改成:
    RemoteInterface server = (RemoteInterface)Naming.lookup("rmi://202.121.76.17/ServerTest");      
      

  4.   

    remoteObject_Skel.class在服务器上。
    remoteObject_Stub.class在客户机上。
    remoteObject_Stub文件和接口定义文件在客户机上也必须放入CLASSPATH中去,才能找到。
    至于策略文件,你按kemble说的去做就行了。
    要是成功了,我和kemble各50分啊。
      

  5.   

    6.1 If you encounter a problem running your RMI server
    The first problem you might encounter is the receipt of a ClassNotFoundException when attempting to bind or rebind a remote object to a name in the registry. This exception is usually due to a malformed codebase property, resulting in the registry not being able to locate the remote object's stubs or other classes needed by the stub. It is important to note that the remote object's stub implements all the same interfaces as the remote object itself, so those interfaces, as well as any other custom classes declared as method parameters or return values, must also be available for download from the specified codebase.Most frequently, this exception is thrown as a result of omitting the trailing slash from the URL value of the property. Other reasons would include: the value of the property is not a URL; the path to the classes specified in the URL is incorrect or misspelled; the stub class or any other necessary classes are not all available from the specified URL.The exception that you may encounter in such a case would look like this: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: examples.callback.MessageReceiverImpl_Stub
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: examples.callback.MessageReceiverImpl_Stub
    java.lang.ClassNotFoundException: examples.callback.MessageReceiverImpl_Stub
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Compiled Code)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Compiled Code)
    at sun.rmi.server.UnicastRef.invoke(Compiled Code)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Compiled Code)
    at java.rmi.Naming.rebind(Compiled Code)
    at examples.callback.MessageReceiverImpl.main(Compiled Code)
    RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: examples.callback.MessageReceiverImpl_Stub6.2 If you encounter a problem running your RMI client
    The second problem you could encounter is the receipt of a ClassNotFoundException when attempting to lookup a remote object in the registry. If you receive this exception in a stacktrace resulting from an attempt to run your RMI client code, then your problem is the CLASSPATH with which your RMI registry was started. See requirement C in section 6.0. Here is what the exception will look like:java.rmi.UnmarshalException: Return value class not found; nested exception is:
    java.lang.ClassNotFoundException: MyImpl_Stub
    at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:109
    at java.rmi.Naming.lookup(Naming.java:60)
    at RmiClient.main(MyClient.java:28)
      

  6.   

    我摘自java 1。4。0 DOCS
      

  7.   

    必须做Policy文件,可以用在windows运行里面运行policytool生成。
      

  8.   

    Do u receive it?If ok, please let me know. I just want to see some rmi demo.