0

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.)

Wes
  • 537
  • 4
  • 25
  • How are you running your application? If you're still getting the same error, it's because there's still a classpath issue somewhere. – Patrick Grimard Aug 04 '14 at 18:11

1 Answers1

0

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.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
  • That's what I thought as well. I have `compile "org.hibernate:hibernate-entitymanager:4.1.10.FINAL"` in my gradle.build file and as a result the jboss-logging JAR you indicated **is** included in the WEB-INF/lib directory when I package up project into a WAR. Would adding the JAR file locally versus getting it through a transitive dependency make a difference? – Wes Aug 04 '14 at 18:55
  • When are you getting the error? Running unit tests? Running your code from the command-line? Running your application in Tomcat or some other web server? – Luke Woodward Aug 04 '14 at 19:03
  • The error occurs when running the application in Tomcat and I navigate to any page that uses Spring MVC. To be specific, it is running as an extension of Blackboard Learn (a Learning Management System for universities). – Wes Aug 04 '14 at 19:05
  • If you restart Tomcat, do you get the same error the first time you navigate to a Spring MVC page? Are there any messages in your application's logs (assuming logging is working at all)? Anything in the Tomcat logs? – Luke Woodward Aug 04 '14 at 19:29
  • Yes, the issue still occurs after restarting Tomcat. This exception is logged in the Tomcat stdout-stderr logs: `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` – Wes Aug 04 '14 at 19:55
  • @whargrove: could you please edit your question to include this exception message and the full stacktrace. Also, is this error message the first error message written to the logs following the Tomcat restart? – Luke Woodward Aug 04 '14 at 20:12
  • I added a link to the full stack trace in the question. Looks like this is an java.security.AccessControlException issue that is causing PropertyContainer to not be initialized. – Wes Aug 04 '14 at 20:27
  • @whargrove: so it is the system property that causes the problem. The next step is clearly to get around that AccessControlException. There should be plenty of Google results to help you there. – Luke Woodward Aug 04 '14 at 20:45