简体   繁体   中英

Caused by: java.lang.ClassNotFoundException: Log

When doing a remote EJB lookup (from JBoss 4.3) in J2SE, I'm encountering the following exception:

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

Here is teh codez, line 44 is the one doing the lookup:

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);
        }
    }
}

I'm confused as to why it's looking for a Log class (and why the exception is not package-qualified)?

ShoppingBasketServiceRemote is just an interface that imports the javax.ejb.Remote annotation and extends another interface - neither make any reference to a Log class? Additionally, you'll see my example only casts the result to Object (but the result is the same if I swap out for the service interface)?

ShoppingBasketServiceRemote is just an interface that imports the javax.ejb.Remote annotation and extends another interface - neither make any reference to a Log class?

  • Examine all the objects referenced in the interface & their transitive dependencies. Something will point to the "Log" class.
  • Also check the remote server for errors, maybe the error is on the remote server
  • Try doing a simple Class.forName("ShoppingBasketServiceRemote") - you might see it failing with the same error.

Additionally, you'll see my example only casts the result to Object (but the result is the same if I swap out for the service interface)?

Casting the object happens after your jvm is able to load the object returned by ic.lookup(Lookup) - so the error will happen whether you cast or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM