我在部署RMI的时候~
start rmiregistry
java -Djava.rmi.server.codebase=http://localhost:8080/server/ ProductServer
这两部都成功了
但是在启动客户端程序
java -Djava.security.policy=client.policy ProductClient
的时候却报错了~好像是连接不上服务器~我想了好久都找不出原因啊
希望您能给我帮助PS:我电脑上的服务器是tomcat,服务器端文件放在tomcat根目录的server目录下
client.policy, ProductClient两个文件在同一个目录下
client.policy的内容是
grant {
permission java.security.AllPermission;
}; 再贴上ProductClient的代码import java.rmi.*;
import java.rmi.server.*;
import javax.naming.*;
import java.util.Scanner;
public class ProductClient
{ /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
System.setProperty("java.security.policy", "client.policy");
System.setSecurityManager(new RMISecurityManager());
//System.setProperty("java.rmi.server.codebase", "http://localhost:8080/server/");
String url="rmi://localhost/";
Scanner yn=new Scanner(System.in);
String choice;
try
{
Context namingContext=new InitialContext();
Product c1=(Product)namingContext.lookup(url+"toaster");
Product c2=(Product)namingContext.lookup(url+"microwave");
System.out.println(c1.getDescription());
System.out.println(c2.getDescription());
choice=yn.nextLine();
}
catch(Exception e)
{
e.printStackTrace();
} }}
start rmiregistry
java -Djava.rmi.server.codebase=http://localhost:8080/server/ ProductServer
这两部都成功了
但是在启动客户端程序
java -Djava.security.policy=client.policy ProductClient
的时候却报错了~好像是连接不上服务器~我想了好久都找不出原因啊
希望您能给我帮助PS:我电脑上的服务器是tomcat,服务器端文件放在tomcat根目录的server目录下
client.policy, ProductClient两个文件在同一个目录下
client.policy的内容是
grant {
permission java.security.AllPermission;
}; 再贴上ProductClient的代码import java.rmi.*;
import java.rmi.server.*;
import javax.naming.*;
import java.util.Scanner;
public class ProductClient
{ /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
System.setProperty("java.security.policy", "client.policy");
System.setSecurityManager(new RMISecurityManager());
//System.setProperty("java.rmi.server.codebase", "http://localhost:8080/server/");
String url="rmi://localhost/";
Scanner yn=new Scanner(System.in);
String choice;
try
{
Context namingContext=new InitialContext();
Product c1=(Product)namingContext.lookup(url+"toaster");
Product c2=(Product)namingContext.lookup(url+"microwave");
System.out.println(c1.getDescription());
System.out.println(c2.getDescription());
choice=yn.nextLine();
}
catch(Exception e)
{
e.printStackTrace();
} }}
C:\Users\zhujianhui>java -Djava.security.policy=client.policy ProductClient
javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOExcepti
on: error during JRMP connection establishment; nested exception is:
java.io.EOFException]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
:101)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.j
ava:185)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at ProductClient.main(ProductClient.java:27)
Caused by: java.rmi.ConnectIOException: error during JRMP connection establishme
nt; nested exception is:
java.io.EOFException
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:286
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
:97)
... 3 more
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:250)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:228
)
... 7 moreC:\Users\zhujianhui>java -Djava.security.policy=client.policy ProductClientd
Exception in thread "main" java.lang.NoClassDefFoundError: ProductClientd
Caused by: java.lang.ClassNotFoundException: ProductClientd
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: ProductClientd. Program will exit.