我是RIM的新手,目前正在http://java.sun.com/docs/books/tutorial/rmi/overview.html
学习本教程我可以启动服务器,如:
C:\Documents and Settings\myHome>java -cp c:\home\ann\src;c:\home\ann\public_ html\classes\compute.jar -Djava.rmi.server.codebase=file:/c:/home/ann/public_htm l/classes/compute.jar -Djava.rmi.server.hostname=localhost -Djava.security.polic y=c:\home\ann\policy\server.policy engine.ComputeEngine ComputeEngine bound
但是,当我尝试运行客户端时,我有例外
access: access allowed (java.lang.RuntimePermission createClassLoader) access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks ) access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks ) access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks ) access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks ) ComputePi exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exce ption is: java.rmi.UnmarshalException: error unmarshalling arguments; nested excep tion is: java.lang.ClassNotFoundException: access to class loader denied at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) at sun.rmi.transport.Transport$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Unknown Source) at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Sou rce) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour ce) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source ) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) 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 java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unkn own Source) at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source) at $Proxy0.executeTask(Unknown Source) at client.ComputePi.main(ComputePi.java:27) Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested ex ception is: java.lang.ClassNotFoundException: access to class loader denied at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) at sun.rmi.transport.Transport$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Unknown Source) at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Sou rce) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour ce) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source ) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: access to class loader denied at sun.rmi.server.LoaderHandler.loadClass(Unknown Source) at sun.rmi.server.LoaderHandler.loadClass(Unknown Source) at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source) at java.rmi.server.RMIClassLoader.loadClass(Unknown Source) at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source) at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at java.io.ObjectInputStream.readClassDesc(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source) ... 10 more Caused by: java.security.AccessControlException: access denied (java.io.FilePerm ission \c:\home\jones\public_html\classes\- read) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at sun.rmi.server.LoaderHandler$Loader.checkPermissions(Unknown Source) at sun.rmi.server.LoaderHandler$Loader.access$000(Unknown Source) ... 21 more
我认为问题是客户端的客户端策略文件(如果我错了请更正),正如我们从堆栈跟踪中看到的那样
Caused by: java.security.AccessControlException: access denied (java.io.FilePerm ission \c:\home\jones\public_html\classes\- read)
但是,我的client.policy文件看起来像
grant codeBase "file:/c:/home/jones/public_html/classes/-" { permission java.security.AllPermission; }; grant{ permission java.net.SocketPermission "127.0.0.1:1024-65535", "connect,resolve"; };
codeBase的AllPermission“文件:/ c:/ home / jones / public_html / classes /-".
那么,我是否设置了错误的codeBase权限,那么客户端应用程序需要更多权限吗?
感谢!!!
<小时/> 更新: 如果我将client.policy文件移动到C:\ Program Files \ Java \ jre6 \ lib \ security和 我用
启动客户端
C:\Documents and Settings\jianzhang>java -cp c:\home\jones\src;c:\home\jones\pub lic_html\classes\compute.jar -Djava.rmi.server.codebase=file:/c:/home/jones/publ ic_html/classes/ -Djava.security.policy=client.policy -Djava.security.debug=acce ss,failure client.ComputePi localhost 45
我得到了例外
ComputePi exception: java.security.AccessControlException: access denied (java.net.SocketPermission 1 27.0.0.1:1099 connect,resolve) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkConnect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.(Unknown Source) at java.net.Socket.(Unknown Source) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S ource) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S ource) at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source) at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source) at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source) at sun.rmi.server.UnicastRef.newCall(Unknown Source) at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source) at client.ComputePi.main(ComputePi.java:25)
但是,client.policy文件已指定
grant{ permission java.net.SocketPermission "127.0.0.1:1024-65535", "connect,resolve"; };
<小时/> 使用完整堆栈跟踪更新 这是完整的堆栈跟踪,
C:\home\jones\src>java -cp C:\home\jones\src;C:\home\jones\public_html\classes\c ompute.jar;C:\home\jones\public_html\classes -Djava.rmi.server.codebase=file:/C: /home/jones/public_html/classes/ -Djava.security.policy=client.policy -Djava.sec urity.debug=access,failure client.ComputePi localhost 45 access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks ) access: access allowed (java.security.SecurityPermission getProperty.policy.expa ndProperties) access: access allowed (java.security.SecurityPermission getProperty.policy.igno reIdentityScope) access: access allowed (java.security.SecurityPermission getProperty.policy.allo wSystemProperty) access: access allowed (java.util.PropertyPermission sun.security.policy.utf8 re ad) access: access allowed (java.util.PropertyPermission sun.security.policy.numcach es read) access: access allowed (java.util.PropertyPermission java.security.policy read) access: access allowed (java.util.PropertyPermission user.dir read) access: access allowed (java.io.FilePermission C:\home\jones\src\client.policy r ead) access: access allowed (java.io.FilePermission client.policy read) access: access allowed (java.security.SecurityPermission getProperty.policy.url. 1) access: access allowed (java.util.PropertyPermission java.home read) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\lib\se curity\java.policy read) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\lib\se curity\java.policy read) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\lib\se curity\java.policy read) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\lib\se curity\java.policy read) access: access allowed (java.util.PropertyPermission java.ext.dirs read) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\lib\ex t\* read) access: access allowed (java.io.FilePermission C:\WINDOWS\Sun\Java\lib\ext\* rea d) access: access allowed (java.security.SecurityPermission getProperty.policy.url. 2) access: access allowed (java.util.PropertyPermission user.home read) access: access allowed (java.io.FilePermission C:\Documents and Settings\anga ng\.java.policy read) access: access allowed (java.io.FilePermission C:\Documents and Settings\anga ng\.java.policy read) access: access allowed (java.io.FilePermission C:\Documents and Settings\anga ng\.java.policy read) access: access allowed (java.security.SecurityPermission getProperty.policy.url. 3) access: access allowed (java.util.PropertyPermission java.security.auth.policy r ead) access: access allowed (java.security.SecurityPermission getProperty.auth.policy .url.1) access: access allowed (java.lang.RuntimePermission accessClassInPackage.sun.sec urity.provider) access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks ) access: access allowed (java.util.PropertyPermission java.security.egd read) access: access allowed (java.security.SecurityPermission getProperty.securerando m.source) access: access allowed (java.security.SecurityPermission putProviderProperty.SUN ) access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks ) access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks ) access: access allowed (java.util.PropertyPermission * read,write) access: access allowed (java.util.PropertyPermission os.arch read) access: access allowed (java.util.PropertyPermission java.net.preferIPv6Addresse s read) access: access allowed (java.lang.RuntimePermission loadLibrary.net) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\bin\ne t.dll read) access: access allowed (java.util.PropertyPermission java.net.preferIPv4Stack re ad) access: access allowed (java.util.PropertyPermission impl.prefix read) access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks ) access: access allowed (java.util.PropertyPermission sun.net.spi.nameservice.pro vider.1 read) access: access allowed (java.net.SocketPermission myComputer resolve) access: access allowed (java.security.SecurityPermission getProperty.networkaddr ess.cache.ttl) access: access allowed (java.util.PropertyPermission sun.net.inetaddr.ttl read) access: access allowed (java.security.SecurityPermission getProperty.networkaddr ess.cache.negative.ttl) access: access allowed (java.io.FilePermission C:\Documents and Settings\anga ng\Local Settings\Temp read) access: access allowed (java.io.FilePermission C:\Documents and Settings\anga ng\Local Settings\Temp read) access: access allowed (java.io.FilePermission C:\Documents and Settings\anga ng\Local Settings\Temp read) access: access allowed (java.io.FilePermission C:\Documents and Settings\anga ng\Local Settings\Temp read) access: access allowed (java.io.FilePermission C:\DOCUME~1\ang~1\LOCALS~1\Tem p read) access: access allowed (java.util.PropertyPermission java.rmi.server.hostname re ad) access: access allowed (java.io.FilePermission C:\home\jones\src read) access: access denied (java.net.SocketPermission myComputer resolve) java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Unknown Source) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkConnect(Unknown Source) at java.net.InetAddress.getLocalHost(Unknown Source) at sun.rmi.transport.tcp.TCPEndpoint.(Unknown Source) at java.rmi.registry.LocateRegistry.getRegistry(Unknown Source) at java.rmi.registry.LocateRegistry.getRegistry(Unknown Source) at java.rmi.registry.LocateRegistry.getRegistry(Unknown Source) at client.ComputePi.main(ComputePi.java:24) access: access allowed (java.security.SecurityPermission getPolicy) access: access allowed (java.io.FilePermission C:\home\jones\src read) access: domain that failed ProtectionDomain (file:/C:/home/jones/src/ ) sun.misc.Launcher$AppClassLoader@1b90b39 java.security.Permissions@d70d7a ( (java.lang.RuntimePermission stopThread) (java.lang.RuntimePermission exitVM) (java.io.FilePermission \C:\home\jones\src\- read) (java.util.PropertyPermission line.separator read) (java.util.PropertyPermission java.vm.version read) (java.util.PropertyPermission java.vm.specification.version read) (java.util.PropertyPermission java.vm.specification.vendor read) (java.util.PropertyPermission java.vendor.url read) (java.util.PropertyPermission java.vm.name read) (java.util.PropertyPermission os.name read) (java.util.PropertyPermission java.vm.vendor read) (java.util.PropertyPermission path.separator read) (java.util.PropertyPermission java.specification.name read) (java.util.PropertyPermission os.version read) (java.util.PropertyPermission os.arch read) (java.util.PropertyPermission java.class.version read) (java.util.PropertyPermission java.version read) (java.util.PropertyPermission file.separator read) (java.util.PropertyPermission java.vendor read) (java.util.PropertyPermission java.vm.specification.name read) (java.util.PropertyPermission java.specification.version read) (java.util.PropertyPermission java.specification.vendor read) (java.net.SocketPermission localhost:1024- listen,resolve) ) access: access allowed (java.util.PropertyPermission java.rmi.server.useLocalHos tName read) access: access allowed (java.util.PropertyPermission sun.rmi.transport.logLevel read) access: access allowed (java.util.PropertyPermission sun.rmi.log.useOld read) access: access allowed (java.util.PropertyPermission java.util.logging.manager r ead) access: access allowed (java.lang.RuntimePermission setContextClassLoader) access: access allowed (java.lang.RuntimePermission shutdownHooks) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.PropertyPermission java.util.logging.config.cl ass read) access: access allowed (java.util.PropertyPermission java.util.logging.config.fi le read) access: access allowed (java.util.PropertyPermission java.home read) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\lib\lo gging.properties read) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\lib\lo gging.properties read) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\lib\lo gging.properties read) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.PropertyPermission line.separator read) access: access allowed (java.util.PropertyPermission line.separator read) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.PropertyPermission sun.rmi.transport.tcp.logLe vel read) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.PropertyPermission sun.rmi.transport.tcp.maxCo nnectionThreads read) access: access allowed (java.util.PropertyPermission sun.rmi.transport.tcp.threa dKeepAliveTime read) access: access allowed (java.util.PropertyPermission sun.rmi.transport.proxy.log Level read) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.PropertyPermission sun.rmi.transport.proxy.con nectTimeout read) access: access allowed (java.util.PropertyPermission sun.rmi.transport.proxy.eag erHttpFallback read) access: access allowed (java.util.PropertyPermission http.proxyHost read) access: access allowed (java.util.PropertyPermission proxyHost read) access: access allowed (java.util.PropertyPermission java.rmi.server.disableHttp read) access: access allowed (java.util.PropertyPermission sun.rmi.transport.tcp.readT imeout read) access: access allowed (java.util.PropertyPermission sun.rmi.server.logLevel rea d) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.PropertyPermission java.rmi.server.ignoreStubC lasses read) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.PropertyPermission sun.rmi.client.logCalls rea d) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.PropertyPermission java.rmi.server.hostname re ad) access: access allowed (java.util.PropertyPermission sun.rmi.transport.connectio nTimeout read) access: access allowed (java.util.PropertyPermission sun.rmi.transport.tcp.hands hakeTimeout read) access: access allowed (java.util.PropertyPermission sun.rmi.transport.tcp.respo nseTimeout read) access: access allowed (java.util.logging.LoggingPermission control) access: access allowed (java.util.PropertyPermission sun.rmi.runtime.schedulerTh reads read) access: access allowed (java.lang.RuntimePermission sun.rmi.runtime.RuntimeUtil. getInstance) access: access allowed (java.net.SocketPermission localhost resolve) access: access allowed (java.lang.RuntimePermission loadLibrary.net) access: access allowed (java.io.FilePermission C:\Program Files\Java\jre6\bin\ne t.dll read) access: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve) java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Unknown Source) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkConnect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.(Unknown Source) at java.net.Socket.(Unknown Source) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S ource) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S ource) at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source) at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source) at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source) at sun.rmi.server.UnicastRef.newCall(Unknown Source) at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source) at client.ComputePi.main(ComputePi.java:25) access: access allowed (java.security.SecurityPermission getPolicy) access: access allowed (java.io.FilePermission C:\home\jones\src read) access: domain that failed ProtectionDomain (file:/C:/home/jones/src/ ) sun.misc.Launcher$AppClassLoader@1b90b39 java.security.Permissions@77158a ( (java.lang.RuntimePermission stopThread) (java.lang.RuntimePermission exitVM) (java.io.FilePermission \C:\home\jones\src\- read) (java.util.PropertyPermission line.separator read) (java.util.PropertyPermission java.vm.version read) (java.util.PropertyPermission java.vm.specification.version read) (java.util.PropertyPermission java.vm.specification.vendor read) (java.util.PropertyPermission java.vendor.url read) (java.util.PropertyPermission java.vm.name read) (java.util.PropertyPermission os.name read) (java.util.PropertyPermission java.vm.vendor read) (java.util.PropertyPermission path.separator read) (java.util.PropertyPermission java.specification.name read) (java.util.PropertyPermission os.version read) (java.util.PropertyPermission os.arch read) (java.util.PropertyPermission java.class.version read) (java.util.PropertyPermission java.version read) (java.util.PropertyPermission file.separator read) (java.util.PropertyPermission java.vendor read) (java.util.PropertyPermission java.vm.specification.name read) (java.util.PropertyPermission java.specification.version read) (java.util.PropertyPermission java.specification.vendor read) (java.net.SocketPermission localhost:1024- listen,resolve) ) ComputePi exception: java.security.AccessControlException: access denied (java.net.SocketPermission 1 27.0.0.1:1099 connect,resolve) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkConnect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.(Unknown Source) at java.net.Socket.(Unknown Source) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S ource) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S ource) at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source) at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source) at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source) at sun.rmi.server.UnicastRef.newCall(Unknown Source) at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source) at client.ComputePi.main(ComputePi.java:25)
第80行:
access: access allowed (java.net.SocketPermission myComputer resolve)
然而从第99行到第111行
access: access denied (java.net.SocketPermission myComputer resolve) java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Unknown Source) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkConnect(Unknown Source) at java.net.InetAddress.getLocalHost(Unknown Source) at sun.rmi.transport.tcp.TCPEndpoint.(Unknown Source) at java.rmi.registry.LocateRegistry.getRegistry(Unknown Source) at java.rmi.registry.LocateRegistry.getRegistry(Unknown Source) at java.rmi.registry.LocateRegistry.getRegistry(Unknown Source) at client.ComputePi.main(ComputePi.java:24)
问题解决了,请参阅 my another post
答案 0 :(得分:1)
你如何启动客户?您在启动客户端时是否指定了策略文件?
启动客户端的命令行应如下所示:
java -cp c:\home\jones\src;c:\home\jones\public_html\classes\compute.jar
-Djava.rmi.server.codebase=file:/c:/home/jones/public_html/classes/
-Djava.security.policy=client.policy
client.ComputePi zaphod.east.sun.com 45
更新:您写道:
如果我将client.policy文件移动到
C:\Program Files\Java\jre6\lib\security
您需要将示例中的路径(c:\home\jones
等)更改为您在计算机上使用的实际路径(代码库和安全文件所在的位置)。