【问题标题】:Adding client remote interface class to classpath on run time and lookup在运行时和查找时将客户端远程接口类添加到类路径
【发布时间】:2016-11-29 20:26:58
【问题描述】:

这是我的代码:

public class MyLoader  extends URLClassLoader
{
public MyLoader  (URL[] urls)
    {
        super (urls);
    }
    public void addFile (String path) throws MalformedURLException
    {

        addURL (new URL (path));
    }
}

首先我加载接口类:

URL urls [] = {};
MyLoader cl = new MyLoader (urls);
cl.addJar("jar:file:///c:/jars/myjar.jar!/");
cl.loadClass ("lebj.interfaces.RRServices");
//no fails here

然后我尝试查找并获取RemoteInterface:

 Object home = loginInitialContext.lookup(JNDI);
EJBHome theHome = (EJBHome) PortableRemoteObject.narrow(home, EJBHome.class);
EJBMetaData md = theHome.getEJBMetaData();          
EJBHome homeInterface = md.getEJBHome();

 md.getRemoteInterfaceClass();// ERROR

这是错误:

weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Unable to load remote interface: java.lang.ClassNotFoundException: lebj.interfaces.RRServices ]
    at weblogic.ejb20.internal.EJBMetaDataImpl.getRemoteInterfaceClass(EJBMetaDataImpl.java:115)

(如果我手动将 jar 添加到 eclipse 项目类路径中,那么它可以工作)

【问题讨论】:

  • 非常智能在不评论的情况下对评论投反对票
  • 尝试不带jar: 和尾随!/
  • 请提供堆栈跟踪的其余部分。您需要将该类加载器用于所有内容,包括执行查找代码的类。仅仅调用cl.loadClass() 并不能完成任何事情,尤其是当您丢弃结果时。
  • 堆栈跟踪中没有更多内容,以下 2 行来自我上面的代码,

标签: java ejb weblogic rmi


【解决方案1】:

添加一个类加载器并通过它加载一个类并不构成“在运行时将客户端远程接口类添加到类路径”,除非所有使用该远程接口的类都是通过相同的类加载器。

【讨论】:

  • 所以我的选择是使用 SystemClassLoader?
  • 或者我的答案在“除非”之后的部分。
猜你喜欢
  • 1970-01-01
  • 2010-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-31
相关资源
最近更新 更多