Error java.lang.NoClassDefFoundError on org.springframework.webflow.util.RandomGuid

Cédric Girard picture Cédric Girard · Dec 17, 2008 · Viewed 20.7k times · Source

I am sorry, my question is stupid, but I am not able to answer it, as a java illiterate. I run a tomcat (5) on CentOS5 (for a CAS server), and when I try to open this URL http://192.168.1.17:8080/cas-server-webapp-3.3.1/login I get this error :

first error: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.webflow.util.RandomGuid

and root error: org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.webflow.util.RandomGuid

$CLASSPATH is empty, and it seems to be a problem, but I don't know what to put in it.

EDIT: Jared is right, my hosts files defined 127.0.0.1 as localhost, and now it work very well!

Answer

Jared picture Jared · Jan 12, 2009

It is important to keep two or three different exceptions strait in our head in this case:

  1. java.lang.ClassNotFoundException This exception indicates that the class was not found on the classpath. This indicates that we were trying to load the class definition, and the class did not exist on the classpath.

  2. java.lang.NoClassDefFoundError This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it. This is different than saying that it could not be loaded from the classpath. Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying again, but we're not even going to try to load it, because we failed loading it earlier. The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.

That being said, another answer poster indicates that the RandomGUID requires a call to InetAddress.getLocalHost(). On many operating systems, this would trigger a host lookup that would use the hosts file (/etc/hosts on *NIX systems, %WINDOWS%/system32/drivers/etc/HOSTS on a Windows system.)

I have seen similar errors quite frequently when that file incorrectly defines the localhost address. 127.0.0.1 should point to 'localhost' (and probably also localhost.localdomain.) It should NOT point to the actual host name of the machine (although for some reason, many older RedHat Linux installers liked to set it incorrectly.)