java RMI -意外错误

cbjzeqam  于 2022-11-20  发布在  Java
关注(0)|答案(3)|浏览(252)

我一直在努力创建一个示例RMI项目有一段时间了,现在有几个小时的困难与以下错误。如果你们中的任何人可以指出我的错误,我将不胜感激。我将张贴修剪代码与错误。
提前感谢您抽出时间。
PrimeFinder.java

import //irrelevant

public interface PrimeFinder extends Remote 
{
    public List<Integer> findPrime (int startPoint, int endPoint )
        throws RemoteException;
}

PrimeFinderService.java

import //irrelevant

public class PrimeFinderService extends UnicastRemoteObject
implements PrimeFinder
{
    public PrimeFinderService () throws RemoteException
    {
        super();
    }

    public List<Integer> findPrime(int startPoint, int endPoint)
            throws RemoteException {

        // Irrelevant
    }

    public static void main ( String args[] ) throws Exception
    {
        if (System.getSecurityManager() == null)
            System.setSecurityManager ( new RMISecurityManager() );

        PrimeFinderService svr = new PrimeFinderService();
        Naming.bind ("PowerService", svr);

        System.out.println ("Service bound....");
    }
}

策略

grant {
    permission java.security.AllPermission; }

要命的错误是:

Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: access to class loader denied
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
    at sun.rmi.transport.Transport$1.run(Transport.java:177)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
    at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
    at java.rmi.Naming.bind(Naming.java:128)
    at q7.PrimeFinderService.main(PrimeFinderService.java:69)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: access to class loader denied
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
    at sun.rmi.transport.Transport$1.run(Transport.java:177)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.ClassNotFoundException: access to class loader denied
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:445)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:182)
    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:1592)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1513)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1749)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
    ... 12 more
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission /home/cem/workspace/OBSS_q7/bin/q7/- read)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:393)
    at java.security.AccessController.checkPermission(AccessController.java:553)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at sun.rmi.server.LoaderHandler$Loader.checkPermissions(LoaderHandler.java:1173)
    at sun.rmi.server.LoaderHandler$Loader.access$000(LoaderHandler.java:1127)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:409)
    ... 21 more

编辑1:
我试图克服的错误线是:

Caused by: java.security.AccessControlException: access denied (java.io.FilePermission /home/cem/workspace/OBSS_q7/bin/q7/- read)

我在我的.policy文件中尝试了至少10种不同的方法-所有这些方法都以同样的问题告终。我在教程中尝试了所有我找到的方法,我相信可以肯定地说,问题不在.policy文件中。
我还干预了代码库,给代码库错误的结果是不同的错误,所以这也不可能是它。
仍在寻找创意^^
干杯!干杯!

pxy2qtax

pxy2qtax1#

删除SecurityManager,或者自己编写一个赠款该权限的安全策略文件。

5sxhfpxr

5sxhfpxr2#

该问题与linux文件系统权限有关,更改权限可解决该问题。

blpfk2vs

blpfk2vs3#

如果有人在Windows上偶然发现了这个问题,那么两个词...Windows Defender。它可能只是删除了您的项目文件。
所以只要重建你的项目。不,不是“重建”,只是完全“重建”。
Windows Defender可能会删除您的项目的可执行文件,如果他们进入高CPU使用率。所以我也总是建议把您的项目的目录作为一个例外。

相关问题