Mantis - Resin
Viewing Issue Advanced Details
3252 major always 01-14-09 01:30 06-18-09 15:32
GreenEyed  
ferg  
normal  
closed 3.2.1  
unable to reproduce  
none    
none 4.0.1  
0003252: Resin embedded cannot find classes in WEB-INF/lib using Class.forName from the very same .jar
When trying to load a class using Class.forName inside a class that has been loaded from WEB-INF/lib, a ClassNotFound is thrown even if the class is inside the very same .jar file of the class performing the Class.forName.

The application works fine if executed using 3.2.1 the regular way. It just happens in embedded mode.
Here it is an example stack trace. The class calling Class.forName (org.leaf.xml.ClassSource) is inside a .jar file located in WEB-INF/lib, and the class that is not found (org.leaf.util.ConnectionManagementHelper) is packaged in the same jar file.
*********************************************************************
WARN: java.lang.NoClassDefFoundError:
org/leaf/util/ConnectionManagementHelper$SQLAction
java.lang.NoClassDefFoundError:
org/leaf/util/ConnectionManagementHelper$SQLAction
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at org.leaf.xml.ClassSource.getSource(ClassSource.java:134)
         at org.leaf.xml.ClassSource.getXMLSource(ClassSource.java:264)
...
Caused by: java.lang.ClassNotFoundException:
org.leaf.util.ConnectionManagementHelper$SQLAction
         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.loadClassInternal(Unknown Source)
         ... 27 more
*********************************************************************

Notes
(0004082)
ferg   
06-18-09 15:32   
server/1e81

Checked with jar in WEB-INF/lib for ResinEmbed (launched independently), and the subclasses load correctly.

From the bug report, the "NoClassDefFoundError" is a tricky JVM message. The classname in the exception isn't the problem class. The problem class is a class used by the named class. In other words, some class inside SQLAction (or ConnectionManagementHelper.) It's possible the dependent jar wasn't available to the ResinEmbed.

Unfortunately, the JVM's error message doesn't tell you which actual class failed to load.