在运行时和查找时将客户端远程接口类添加到类路径

时间:2016-07-26 09:10:33

标签: java ejb weblogic rmi

这是我的代码:

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项目类路径,那么它可以工作)

1 个答案:

答案 0 :(得分:0)

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