简体   繁体   English

java RMI - 意外错误

[英]java RMI - unexpected error

I have been working on to create a sample RMI project for a while and having difficulty with the following error for a few hours now.一段时间以来,我一直致力于创建示例 RMI 项目,现在几个小时以来一直难以解决以下错误。 If anyone of you can point me towards my mistake, I will be grateful.如果你们中的任何人能指出我的错误,我将不胜感激。 I will be posting the trimmed code with the error.我将发布带有错误的修剪代码。

Thanks in advance for your time.在此先感谢您的时间。

PrimeFinder.java PrimeFinder.java

import //irrelevant

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

PrimeFinderService.java 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....");
    }
}

.policy 。政策

grant {
    permission java.security.AllPermission; }

The error that is killing me:杀死我的错误:

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

Edit 1:编辑 1:

The error line that I'm trying to overcome is:我试图克服的错误行是:

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

I have tried at least 10 different approaches in my.policy file - all of which ended up with the same problem.我在 my.policy 文件中尝试了至少 10 种不同的方法——所有这些方法都以同样的问题告终。 I have tried anything in the tutorials I have found and it's I believe safe to say that the problem doesn't lie in.policy file.我已经尝试了我找到的教程中的任何内容,我相信可以肯定地说问题不在 .policy 文件中。

I have also meddled with the codebase, giving the codebase wrong ends up with different errors so that can't be it either.我也干预了代码库,给代码库错误最终导致不同的错误,所以这也不是。

Still looking for ideas ^^仍在寻找想法^^

Cheers !干杯!

摆脱SecurityManager,否则自己编写一个授予该权限的安全策略文件。

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

If someone stumbles upon the issue on Windows, then two words... Windows Defender .如果有人在 Windows 上偶然发现了这个问题,那么两个词...... Windows Defender It probably just deleted your project files.它可能只是删除了您的项目文件。

So just rebuild your project.所以只需重建你的项目。 No not "build", just entirely " rebuild ".不,不是“构建”,只是完全“重建”。

Windows Defender might delete your project' executables if they went into high CPU usage. Windows 如果项目的 CPU 使用率很高,Defender 可能会删除它们。 So I also always suggest putting your project' directory as an exception.所以我也总是建议把你的项目目录作为一个例外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM