zoukankan      html  css  js  c++  java
  • openfire 部署后报错: java.lang.IllegalArgumentException: interface xx is not visible from class loader

    该异常是创建代理时加载接口的类加载器与创建时传入的不一致。

    在本地eclipse做openfire二次开发,本地运行没错,部署到服务器上后报异常:

         java.lang.IllegalArgumentException: interface xx is not visible from class loader。

    根据异常信息,可知是动态代理时出错的。而在之前部署过却没有这异常发生。

    从日志上分析,可以找到抛异常的地方是:

    Class<?> java.lang.reflect.Proxy.getProxyClass0(ClassLoader loader, Class<?>... interfaces);
     
    由于服务器上不能断点分析,以及无法修改jdk添加日志,通过复制关键代码到自己代码开始抛出异常处打印日志,发现:
                Class<?> interfaceClass = null;
                try {
                    interfaceClass = Class.forName(interfaceName, false, loader);
                } catch (ClassNotFoundException e) {
                }
                if (interfaceClass != interfaces[i]) {
                    throw new IllegalArgumentException(
                        interfaces[i] + " is not visible from class loader");
                }        
    interfaceClass 为null值。

    然后对比之前的开发代码:
    之前:
    public RPCGameAction gameAction = (RPCGameAction) Container
                .createRemoteService(RPCGameAction.class, "gamecenter");
    
    
    
    现在:
    public RPCGameAction getGameAction(String prefix)
        {
            
            return (RPCGameAction) Container
                    .createRemoteService(RPCGameAction.class, prefix);
        }

    而创建代理的代码中的获取类加载器的代码为:
    ClassLoader loader = Thread.currentThread().getContextClassLoader();

     前者会在初始化的时候已经创建好,而后者会根据运行时的ClassLoader而创建,而openfire加载插件的类加载器跟运行的不一致,从而导致创建失败。

    解决的方法可以是:RPCGameAction 这个代理随插件启动而创建到内存中;

             把接口所处的jar包放到../openfire/lib 目录下。

     
  • 相关阅读:
    计算机的启动过程
    project
    ERROR
    告别,是另一种体验
    Kean博客2006年9月-2007年8月链接
    AutoCAD .NET开发大师Kean有价值的博客 2006年8月 .NET内容整理
    VS2010 VS2012拖拽NumericUpDown控件直接卡死的解决办法
    2006-7有价值的Kean博客——Calling ObjectARX functions from a .NET Application(PInvoke)
    使用NetApi渲染Cad模型
    Kean专题:拖动一个属性块(JIG拖拽)
  • 原文地址:https://www.cnblogs.com/qingyibusi/p/7910941.html
Copyright © 2011-2022 走看看