Issue with NoClassDefFoundError error in a web environment Spring/Wicket/Derby/Jetty?

The message Could not initialize class org.apache.derby.jdbc. EmbeddedDriver means that at that point the JVM has already tried and failed to initialize this class.

The message Could not initialize class org.apache.derby.jdbc. EmbeddedDriver means that at that point the JVM has already tried and failed to initialize this class. The JVM will fail to initialize a class if an exception is thrown and not caught within the class's static initializer.

The only reasons that the JVM would be attempting to initializing the EmbeddedDriver class more than once would be: some exception initializing the class was thrown, this exception was caught elsewhere and the program continued, some exception initializing the class was thrown, but the program then entered a finally block, and within this finally block the JVM attempted to load the class again. The static initializer for EmbeddedDriver (source) calls a boot() method. However, this boot() method calls a fair bit of other code, so it's difficult to tell where the problem could be.

I had a look at some of the source of org.apache.commons.dbcp. BasicDataSource, but it seems the line numbers in your stacktrace don't agree with the source. I don't know which version of commons-dbcp you are using.

If you've got no other output messages nor stacktraces to go on, your best bet may be to attach the source of Derby to your debugger and step through it to see what's going on. As an aside, it's quite possible to 'print' a class that hasn't been initialized. Consider the following classes: class St1 { static { System.out.

Println("In static initializer"); } } public class St2 { public static void main(String args) { System.out. Println(St1. Class); System.out.

Println(new St1()); } } When I run class St2, I get the following output: class St1 In static initializer St1@65690726.

Good comment. That is what I was thinking. It is funny because it didn't complain that commons-pool wasn't added which I think is a dependency of dbcp.

I added commons-pool but I still get the error. I will keep digging. I should have all of the dependencies.

– Berlin Brown Apr 8 '11 at 19:22.

So the 'Could not initialize class org.apache.derby.jdbc. EmbeddedDriver' error was actually the main symptom of some other, less obvious, class loading issues. I was using Jetty as the web server and Spring as the framework under java6.

I believe there was a class loading issue, related to the MBeanServer class. And I did ignore an error that happened at startup: "Caused by: java.lang. LinkageError: loader constraint violation: loader (instance of org/mortbay/jetty/webapp/WebAppClassLoader) previously initiated loading for a different type with name "javax/management/MBeanServer" at java.lang.ClassLoader.

DefineClass1(Native Method) at java.lang.ClassLoader. DefineClassCond(ClassLoader. Java:632) at java.lang.ClassLoader.

DefineClass(ClassLoader. Java:616) at java.security. SecureClassLoader.

DefineClass(SecureClassLoader. Java:141)" I searched for the class in my WEB-INF/lib directory.It was included as part of mx4j:jar. Mx4j was a dependency for jetty-management.jar.

I didn't really need jetty-management so I removed that reference from my pom file. Basically the inclusion of MBeanServer (from mx4j) caused some kind of class loading issue where org.apache.derby.jdbc. EmbeddedDriver couldn't be loaded properly.

I removed it from my web application and the application started working properly.

Glad you got it to work! – Bryan Pendleton Apr 11 '11 at 13:59 The error was very misleading and I was so thinking classpath issues. – Berlin Brown Apr 11 '11 at 17:46.

Sometimes these errors are because you have Derby in your classpath twice, somehow. With modern JDKs, Derby's drivers are 'auto-loaded', meaning that the JDK will look for JDBC drivers on the classpath and automatically load them. So you might check your system classpath as well as your application's libraries; perhaps you have a second copy of Derby hidden away somewhere in the path and the exception is trying to tell you that the two versions of Derby are in conflict.

That is certainly possible. – Berlin Brown Apr 8 '11 at 19:23.

Are you sure that your derby. Jar contains the org.apache.derby.jdbc. EmbeddedDriver class?

You may want to check you have the correct version. If you are using Maven to package the application then it is strange that the jar name ends up being derby. Jar with no version number attached to it.

WEB-INF/lib/derby-10.6.1.0. Jar I would have gotten a ClassNotFound exception. Plus, I have a tool at runtime to check that a class is available.

The class is available at runtime, but for some reason, I or Spring can't instantiate it. – Berlin Brown Apr 8 '11 at 17:20 Not sure why you would vote this down in that case, checking to make sure you have the correct version - and that the class exists - is a valid first step for this type of problem. – matt be Apr 8 '11 at 19:45 I said I have the right version and the class exists.

– Berlin Brown Apr 8 '11 at 20:06.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions