NoClassDefFoundError in an ClassLoader for a class already loaded ?

Discussion in 'Java' started by veovis, Apr 7, 2004.

  1. veovis

    veovis Guest

    I use an extended URLClassLoader to load classes from directories not
    included in classpath. Everything works well the following way:

    package A: Included in claspath. To it belong: a starting class Start,
    the classloader Loader, and some other classes.

    package B: Not included in classpath. To it belong (for this
    explanation purpose): classes Master, Slave, AbstractFoo, and Foo
    which extends AbstractFoo.

    packageA.Start instantiates packageA.Loader, loader instantiates
    packageB.Master within a thread, master creates a new Slave wthich in
    turn creates new Foo() as well other objects from inside other
    packages (package A and others..) Everything's fine.

    BUT: let's assume in package A exists class LocalFoo which extends
    whichever packageB.Foo or packageB.AbstractFoo (packageB is not
    included in classpath, remember?).

    When slave instantiates packageA.LocalFoo, following exception is
    generated:
    java.lang.NoClassDefFoundError: packageB/AbstractFoo
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at PackageB.Slave.doSomething(Slave.java:31)
    at PackageB.Master.doSomething(Master.java:19)
    at PackageB.Master.run(Master.java:14)

    Why? What am missing that is very obvious or silly?
    (NOTE: hope explanation above is enough; but I will paste a bit of
    code on demand.)
    Thanks !
     
    veovis, Apr 7, 2004
    #1
    1. Advertising

  2. veovis

    Dave Glasser Guest

    (veovis) wrote on 6 Apr 2004 19:21:34 -0700
    in comp.lang.java.programmer:

    >I use an extended URLClassLoader to load classes from directories not
    >included in classpath. Everything works well the following way:


    <snip>

    This question has been coming up a lot lately. Check groups.google.com
    for a thread in this newsgroup, with the subject "URLClassLoader" and
    see my reply of March 23rd, which explains the concepts involved.

    I'd also advise you to check java.sun.com and/or javaworld.com for
    articles on how classloaders work, particularly how they form a
    tree-like hierachy, and how classes loaded by a classloader can have
    access to classes loaded by their own classloader, or an ancestor of
    their own classloader, but not a descendant of their classloader, nor
    a classloader in a separate branch of the tree. Once you fully
    understand that, using custom classloaders should be very easy for
    you.


    --
    Check out QueryForm, a free, open source, Java/Swing-based
    front end for relational databases.

    http://qform.sourceforge.net
     
    Dave Glasser, Apr 7, 2004
    #2
    1. Advertising

  3. veovis

    Roedy Green Guest

    On 6 Apr 2004 19:21:34 -0700, (veovis) wrote
    or quoted :

    >Why? What am missing that is very obvious or silly?


    One basic is that class1 != Class1 unless they were loaded from the
    same classloader. From the JVM's point of view, they are entirely
    different classes.

    That may be completely irrelevant, but I toss it out.


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Apr 7, 2004
    #3
  4. veovis

    Roedy Green Guest

    On Wed, 07 Apr 2004 05:55:17 GMT, Roedy Green
    <> wrote or quoted :

    >One basic is that class1 != Class1 unless they were loaded from the
    >same classloader. From the JVM's point of view, they are entirely
    >different classes.

    ..

    see http://mindprod.com/jgloss/classloader.html

    for some hints on them.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Apr 7, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp
    Replies:
    6
    Views:
    13,445
    Joseph Millar
    Jul 11, 2003
  2. Replies:
    1
    Views:
    371
    Mike Schilling
    Mar 2, 2005
  3. Replies:
    1
    Views:
    2,152
    Irmen de Jong
    Jun 22, 2004
  4. Replies:
    3
    Views:
    433
    Andrew Thompson
    Feb 12, 2007
  5. Replies:
    1
    Views:
    75
    David Dorward
    Feb 11, 2007
Loading...

Share This Page