3 Replies Latest reply on Apr 13, 2004 12:34 PM by Nicholas Whitehead

    Loading classes via reflection and NoClassDefFoundError

    dlamotta Newbie

      Hello all. I seem to be having trouble with classes loaded via Reflection and I was wondering if anybody in the forum can provide some pointers. The problem is as follows:

      I have class files RedApple.class, GreenApple.class, YellowApple.class sitting on the filesystem where JBoss 4.0 DR3 is running. For all intents and purposes lets say those 3 class files are in /tmp on a Linux machine running Java 1.4.2_03.

      The colored apple classes all extend Apple. Apple, in contrast with the colored apples, lives in a Jar file that has been placed along the FruitBean in the $JBOSS/server/fruits/deploy directory. A helper class to FruitBean (say, FruitHarvester, which is a custom class loader) instantiates colored apples in the following manner:

      1. Reads from a properties file where the colored apple class files are located.
      2. Via an input stream it loads a byte array for the appropriate colored apple we are about to harvest.
      3. FruitHarvester issues a call to ClassLoader.defineClass and passes it the name of the colored apple, the bytes it read from the file, 0 and the length of the byte array.

      If you trace ClassLoader.defineClass you'll see that it makes a call to defineClass0() which is a native call. That is the last call in my stack trace and the exception I get is a NoClassDefFoundError on Apple.

      I have run out of ideas why Apple cannot be seen by JBoss, especially because Apple is in the Jar file I deployed. I have tried putting that same Jar file in the $JBOSS/server/fruits/lib directory, I have tried extracting Apple.class and putting it in that same dir, I have tried putting the Jar file in $JBOSS/lib directly, and none of these things helps JBoss find the Apple class. The properties file is read without a problem and the bytes for the class file are successfully read, the problem is when loading the class. It is as if JBoss has half of what it needs (colored apple class) but it's missing the other half (Apple), even though the later is in the lib directory in a Jar file.

      Please, if anybody has any pointers do let me know. I have ran out of ideas on this problem.


      // David