在J2SE中进行远程EJB查找(来自JBoss 4.3)时,我遇到以下异常:
Exception in thread "main" java.lang.NoClassDefFoundError: LLog;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2499)
at java.lang.Class.getDeclaredField(Class.java:1951)
at java.io.ObjectStreamClass.getDeclaredSUID(ObjectStreamClass.java:1659)
at java.io.ObjectStreamClass.access$700(ObjectStreamClass.java:72)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:480)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:468)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:468)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:365)
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:602)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1706)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1344)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
at java.rmi.MarshalledObject.get(MarshalledObject.java:159)
at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:737)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:654)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.example.ShoppingBasketServiceClient.main(ShoppingBasketServiceClient.java:44)
Caused by: java.lang.ClassNotFoundException: Log
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 32 more
这是代码,第44行是进行查找的代码:
package com.example;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ShoppingBasketServiceClient {
public static void main(String[] args) throws NamingException {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
props.setProperty("java.naming.provider.url", "jnp://localhost:1099");
String Lookup = "ejb/ShoppingBasketService/remote";
try {
InitialContext ic = new InitialContext(props);
// ShoppingBasketServiceRemote shoppingBasketService = (ShoppingBasketServiceRemote) ic.lookup(Lookup);
Object shoppingBasketService = (Object) ic.lookup(Lookup);
} catch (NamingException e) {
System.out.println("Exception:" + e);
}
}
}
我很困惑为什么它正在寻找一个Log类(为什么异常不是包限定的?)
ShoppingBasketServiceRemote
只是一个导入javax.ejb.Remote注释并扩展另一个接口的接口 - 既不对Log类进行任何引用?另外,您将看到我的示例仅将结果转换为Object(但如果我换出服务接口,结果是相同的)?
答案 0 :(得分:1)
ShoppingBasketServiceRemote只是一个导入的界面 javax.ejb.Remote注释并扩展另一个接口 - 两者都没有 提出任何对Log类的引用?
Class.forName("ShoppingBasketServiceRemote")
- 你可能会看到它失败并出现同样的错误。此外,您将看到我的示例仅将结果强制转换为Object (但如果换掉服务接口,结果是一样的)?
在jvm能够加载ic.lookup(Lookup)
返回的对象之后,会抛出对象 - 所以无论你是否投射都会发生错误。