title: Issue with NoClassDefFoundError error in a web environment Spring/Wicket/Derby/Jetty
body: <p>I am trying to build a simple JDBC Spring Template application, the web framework I am using is wicket and under the jetty 6 web server (through the Jetty Maven Plugin).  Also, I am building the app with Eclipse.</p>
  
  <p>For some reason, I am getting a NoClassDefFoundError with the Derby jdbc class.  I am assuming I would get a class not found exception was not found, so am guessing something else is happening.  The derby class is part of the classpath, the WEB-INF/lib directory.  What do you think the issue is?</p>
  
  <p><strong>My thoughts on the problem:</strong>  It is not a "jar not found in the classpath" error but more an issue with Java or spring dynamically loading that class and when it gets loaded.</p>
  
  <p>I am using Eclipse as the development tool but it probably isn't part of the problem.  I am still using Maven on the command line and getting the same issue.</p>
  
  <p>Here is the error:</p>
  
  <p>WicketMessage: Can't instantiate page using constructor public wicketspring.easy.HomePage()</p>
  
  <p>Root cause:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: Could not initialize class org.apache.derby.jdbc.EmbeddedDriver
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Class.java:169)
       at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1130)
       at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
       at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
       at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
       at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:577)
       at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:619)
       at wicketspring.easy.jdbc.JdbcWicketSpringHandler.data(JdbcWicketSpringHandler.java:39)
       at WICKET_wicketspring.easy.jdbc.JdbcWicketSpringHandler$$FastClassByCGLIB$$f1187cb6.invoke(&lt;generated&gt;)
       at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
       at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:319)
       at WICKET_wicketspring.easy.jdbc.JdbcWicketSpringHandler$$EnhancerByCGLIB$$e8f0e174.data(&lt;generated&gt;)
       at wicketspring.easy.HomePage.&lt;init&gt;(HomePage.java:91)
       at wicketspring.easy.HomePage.&lt;init&gt;(HomePage.java:47)
  </code></pre>
  
  <p>Here is the applicationContext.xml for Spring:</p>
  
  <pre><code>&lt;beans&gt;
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
          &lt;property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" /&gt;
          &lt;property name="url"&gt;&lt;value&gt;jdbc:derby:wicketspringdb&lt;/value&gt;&lt;/property&gt;
          &lt;property name="username"&gt;&lt;value&gt;&lt;/value&gt;&lt;/property&gt;
          &lt;property name="password"&gt;&lt;value&gt;&lt;/value&gt;&lt;/property&gt;
      &lt;/bean&gt; 
      &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt; 
  &lt;/beans&gt;
  &lt;beans&gt; 
      &lt;import resource="classpath:common.xml"/&gt;
      &lt;bean id="jdbcHandler" class=wicketspring.easy.jdbc.JdbcWicketSpringHandler"&gt;
          &lt;property name="jdbcTemplate" ref="jdbcTemplate" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  
  
  ...
  Another stack trace system out.
  
  Page.java:74) - At [2b] -- java.lang.NoClassDefFoundError: Could not initialize class org.apache.derby.jdbc.EmbeddedDriver
  java.lang.NoClassDefFoundError: Could not initialize class org.apache.derby.jdbc.EmbeddedDriver
          at wicketspring.easy.HomePage.&lt;init&gt;(HomePage.java:72)
          at wicketspring.easy.HomePage.&lt;init&gt;(HomePage.java:47)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
  39)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorIm
  pl.java:27)
  </code></pre>
  
  <p>...</p>
  
  <p>Here is the java code, the code compiles and I can print out the class but I can't instantiate it.  Strange?</p>
  
  <p>Java Code:</p>
  
  <pre><code>package wicketspring.easy;
  
  import java.util.List;
  
  import org.apache.wicket.Application;
  import org.apache.wicket.PageParameters;
  import org.apache.wicket.markup.html.WebPage;
  import org.apache.wicket.markup.html.basic.Label;
  import org.apache.wicket.markup.html.list.ListItem;
  import org.apache.wicket.markup.html.list.ListView;
  import org.apache.wicket.model.CompoundPropertyModel;
  import org.apache.wicket.proxy.IProxyTargetLocator;
  import org.apache.wicket.proxy.LazyInitProxyFactory;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import model.LoadableDetachableList;
  import model.SelectionOptionBean;
  import wicketspring.easy.jdbc.JdbcWicketSpringHandler;
  import wicketspring.easy.service.IStateListService;
  import wicketspring.easy.service.StateListServiceImpl;
  
  import org.apache.derby.jdbc.EmbeddedDriver;
  
  public class HomePage extends WebPage {
  
      private final JdbcWicketSpringHandler jdbcWicketSpringHandler;
  
      public HomePage(final PageParameters parameters) {
  
          super(parameters);        
          jdbcWicketSpringHandler = (JdbcWicketSpringHandler) LazyInitProxyFactory.createProxy(JdbcWicketSpringHandler.class,
                  new IProxyTargetLocator() {
                      private static final long serialVersionUID = 1L;
                      public Object locateProxyTarget() {
                          return ((WicketApplication) Application.get()).context().getBean("jdbcHandler");
                      }
                  });    
  
          /// WEIRD BECAUSE IT REACHES THIS POINT!!!
          LOGGER.debug("At [1] -- " + EmbeddedDriver.class);
          try {
              LOGGER.debug("At [2] -- " + new org.apache.derby.jdbc.EmbeddedDriver());
          } catch (NoClassDefFoundError ne) {
                  // STACK TRACE ERROR HERE!!!!
              LOGGER.debug("At [2b] -- " + ne);
              ne.printStackTrace();
          } catch (Exception e) {
              LOGGER.debug("At [2] -- " + e);
              e.printStackTrace();
          }
          try {
  
              LOGGER.debug("At -- " + Class.forName("org.apache.derby.jdbc.EmbeddedDriver"));     
          } catch (NoClassDefFoundError ne) {
              LOGGER.debug("At [3b] -- " + ne);
              ne.printStackTrace();
          } catch (Exception e) {
              LOGGER.debug("At [3] -- " + e);
              e.printStackTrace();
          }
  
          /// ERROR FOR STACKOVERFLOW IS GENERATED FROM THIS LINE!!!!
          LOGGER.debug("At HomePage - jdbcHandler [3]: " + jdbcWicketSpringHandler.toStringJdbcTemplate());
          LOGGER.debug("At HomePage - jdbcHandler [3]: " + jdbcWicketSpringHandler.data());        
  
          ...
  
  } // End of Class //
  </code></pre>
  
  <p>Edit:
  I might be missing a jar file that is a dependency of Spring Jdbc or dbcp.</p>
  
  <p>Here is my WEB-INF/lib listing:</p>
  
  <pre><code>antlr-2.7.6.jar
  aopalliance-1.0.jar
  avalon-framework-4.1.3.jar
  axis-1.4.jar
  axis-jaxrpc-1.4.jar
  cglib-nodep-2.2.jar
  commons-collections-3.1.jar
  commons-dbcp-1.2.2.jar
  commons-logging-1.1.jar
  commons-pool-1.3.jar
  derby-10.6.1.0.jar
  dom4j-1.6.1.jar
  hibernate-core-3.5.1-Final.jar
  jetty-6.1.4.jar
  jetty-management-6.1.4.jar
  jetty-util-6.1.4.jar
  jta-1.1.jar
  log4j-1.2.14.jar
  logkit-1.0.1.jar
  mx4j-3.0.1.jar
  mx4j-tools-3.0.1.jar
  servlet-api-2.5-6.1.4.jar
  servlet-api-2.5.jar
  slf4j-api-1.5.8.jar
  slf4j-log4j12-1.4.2.jar
  spring-2.5.6.jar
  spring-aop-2.5.6.jar
  spring-beans-2.5.6.jar
  spring-context-2.5.6.jar
  spring-core-2.5.6.jar
  spring-jdbc-2.5.6.jar
  spring-test-2.5.6.jar
  spring-tx-2.5.6.jar
  testRunWrapper-1.0.0.jar
  wicket-1.4.13.jar
  wicket-ioc-1.4.13.jar
  wicket-spring-1.4.13.jar
  xml-apis-1.0.b2.jar
  </code></pre>