NoClassDefFoundError Using Hibernate

702 Views Asked by At

I'm using Spring 3.1.1.RELEASE and Hibernate 4.1.10.FINAL in a Building Block on Blackboard Learn and getting the following exception:

java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.PropertyContainer

This seems to be a classpath issue, and so I did some digging and added the suggested libraries from this post but the same error occurs.

So my classpath now contains the necessary dependencies, but I am still getting the exception. What are some additional points I can look at to identify and resolve this issue?

Edit: I've verified the jboss-logging JAR is in my classpath.

Edit: Requested Stack Trace: https://gist.github.com/whargrove/79cbc9c5bd65217e3da3

After restarting Tomcat and re-deploying my WAR the following exceptions are observed in the Tomcat logs:

  1. java.security.AccessControlException: access denied ("java.util.PropertyPermission" "jboss.i18n.generate-proxies" "write")
  2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/config/spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.PropertyContainer

(Full stack trace available in gist link above.)

1

There are 1 best solutions below

8
On

The message

java.lang.NoClassDefFoundError: Could not initialize class SomeClass

means that the JVM has already tried and failed to perform static initialization on the class SomeClass. There may well be another error which happened earlier on when the JVM tried to load the class the first time.

Taking a look at the source of the PropertyContainer class, the only static intialization is a static initializer that sets a system property, and a line that initializes a logger for the class. Setting a system property will should not cause a problem, so my guess is that the logger class used is missing from your classpath.

The logger class used is org.jboss.logging.Logger. A quick Google for this class suggested a jar named jboss-logging.jar. Try getting a copy of that and adding it to your classpath.

(Incidentally, if you can't find a previous error before the 'Could not initialize class' error, that may well be because the missing JAR affects logging. Logging is something applications tend to assume is always working and can be used everywhere. The exception you are seeing might have been thrown from within a finally block that tried to do some logging when the corresponding try block also tried to do some logging but threw an exception. An exception thrown from within a finally block replaces any exception that had previously been thrown.)

EDIT in response to the stacktrace: I can now see that I was wrong about setting a system property not being the problem! I don't know the first thing about Blackboard Learn, but it is possible that it or something else has tightened up the security in your application and hence caused the above problem.

It does however confirm my belief that the real cause of the problem was before the Could not initialize class message.