首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >java.lang.ClassNotFoundException:拒绝对类加载器的访问

java.lang.ClassNotFoundException:拒绝对类加载器的访问
EN

Stack Overflow用户
提问于 2012-01-12 10:30:56
回答 1查看 3.3K关注 0票数 2

我是一个学习java的学生,我已经创建了4个文件。

  1. hellointerface
  2. remotehelloimpl
  3. helloserver
  4. helloclient

我在eclipse上安装了jr6插件以在默认端口上运行注册表,代码如下所示

代码语言:javascript
复制
package demo.rmi.hello.common;
import java.rmi.Remote;
import java.rmi.RemoteException;


public interface helloInterface extends Remote {

    /** This is a sample method. Delete it and add one of your own. */
    public String simpleRemoteMethod(String arg) throws RemoteException;
    public String say() throws RemoteException;

}

remotehelloimpl

代码语言:javascript
复制
 package demo.rmi.hello.server;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import demo.rmi.hello.common.helloInterface;
public class remotehelloImpl extends UnicastRemoteObject implements
helloInterface {
String message;
protected remotehelloImpl(String msg) throws RemoteException {
//super();
// TODO Auto-generated constructor stub
message=msg;
}
public String say() throws RemoteException {
// TODO Auto-generated method stub
return message;
}
@Override
public String simpleRemoteMethod(String arg) throws RemoteException {
    // TODO Auto-generated method stub
    return null;
}
}

helloserver的代码

代码语言:javascript
复制
package demo.rmi.hello.server;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import demo.rmi.hello.common.helloInterface;
public class helloserver {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setSecurityManager(new RMISecurityManager());
try {
helloInterface h = new remotehelloImpl("Hello,From Me!");
Naming.rebind("rmi://localhost:1099/HelloService", h);
System.out.println ("Server is connected and ready for operation.");
}
catch (Exception e) {
System.out.println ("Server not connected: " + e);
}
}
}

*code for helloclient*

代码语言:javascript
复制
package demo.rmi.hello.client;
    import java.rmi.Naming;
    import java.rmi.RMISecurityManager;
    import demo.rmi.hello.common.helloInterface;
    public class helloclient {
    /**
    * @param args
    */
    public static void main (String[] argv) {
    System.setSecurityManager(new RMISecurityManager());
    try {
    helloInterface hello =(helloInterface) Naming.lookup ("rmi://localhost/HelloService");
    System.out.println (hello.say());
    }
    catch (Exception e){
    System.out.println ("HelloClient exception: " + e);}
    }
    }

我有两个安全策略(在Eclipse上自动生成)策略,一个 //文件是由RMI生成的。

代码语言:javascript
复制
///////////////////////////////////////////////////////////////
// This is a sample policy file that grants the application all permissions. 
// A policy file is needed by the RMISecurityManager and your application might
// not work after installing the RMISecurityManager unless you provide a 
// security policy file at launch.
//
// You can configure the security policy of a launched application using either
// the RMI Launcher or by manually setting the java.security.policy property.
//
// SECURITY NOTE: This security policy is good for development. For deployment
// you may need a stricter security policy.
//
// For more information see:
//    http://java.sun.com/docs/books/tutorial/rmi/running.html
//    http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html
// 

grant {
    permission java.security.AllPermission;

    // Other options:
    // permission java.net.SocketPermission "127.0.0.1:1024-", "accept, connect, listen, resolve";
    // permission java.net.SocketPermission "localhost:1024-", "accept, connect, listen, resolve";

    // From http://java.sun.com/docs/books/tutorial/rmi/running.html
    // Copyright 1995-2005 Sun Microsystems, Inc. Reprinted with permission 

    // permission java.net.SocketPermission "*:1024-65535", "connect,accept";
    // permission java.net.SocketPermission "*:80", "connect";

    // permission java.net.SocketPermission "*:1024-65535", "connect,accept";
    // permission java.io.FilePermission "c:\\home\\ann\\public_html\\classes\\-", "read";
    // permission java.io.FilePermission "c:\\home\\jones\\public_html\\classes\\-", "read";
};

* policy2

代码语言:javascript
复制
   // This file was generated by the RMI Plugin for Eclipse.

///////////////////////////////////////////////////////////////
// This is a sample policy file that grants the application all permissions. 
// A policy file is needed by the RMISecurityManager and your application might
// not work after installing the RMISecurityManager unless you provide a 
// security policy file at launch.
//
// You can configure the security policy of a launched application using either
// the RMI Launcher or by manually setting the java.security.policy property.
//
// SECURITY NOTE: This security policy is good for development. For deployment
// you may need a stricter security policy.
//
// For more information see:
//    http://java.sun.com/docs/books/tutorial/rmi/running.html
//    http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html
// 

grant {
    permission java.security.AllPermission;

    // Other options:
    // permission java.net.SocketPermission "127.0.0.1:1024-", "accept, connect, listen, resolve";
    // permission java.net.SocketPermission "localhost:1024-", "accept, connect, listen, resolve";

    // From http://java.sun.com/docs/books/tutorial/rmi/running.html
    // Copyright 1995-2005 Sun Microsystems, Inc. Reprinted with permission 

    // permission java.net.SocketPermission "*:1024-65535", "connect,accept";
    // permission java.net.SocketPermission "*:80", "connect";

    // permission java.net.SocketPermission "*:1024-65535", "connect,accept";
    // permission java.io.FilePermission "c:\\home\\ann\\public_html\\classes\\-", "read";
    // permission java.io.FilePermission "c:\\home\\jones\\public_html\\classes\\-", "read";
};

我首先启动注册表,然后启动服务器,但我得到了以下错误:

代码语言:javascript
复制
Server not connected: 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
EN

回答 1

Stack Overflow用户

发布于 2012-02-08 09:20:52

看看this post,它谈到了“拒绝对类加载器的访问”的问题。

此外,您还没有在客户端代码中指定端口号1099。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8833555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档