0

Created a gwt maven project using the archetype gwt-maven-plugin 2.5.0.

GWT server side depends on BoneCP (A ServletContextListener is supposed to instantiate a connection pool). BoneCP depends on slf4j-api. Starting DevMode throws NoClassDefFoundError, although slf4j-api is added as maven dependency, just as BoneCP is:

Starting Jetty on port 8888
   [WARN] failed com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload@12271e{/,/home/user/workspace/project/target\moduleName-0.0.1-SNAPSHOT}
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.jolbox.bonecp.BoneCPConfig.<clinit>(BoneCPConfig.java:62)
    at my.group.artifact.server.db.ConnectionPool.<init>(ConnectionPool.java:41)
    at my.group.artifact.server.db.ConnectionPool.getInstance(ConnectionPool.java:23)
    at my.group.artifact.server.MyServletContextListener.contextInitialized(MyServletContextListener.java:26)

Checked that org.slf4j.LoggerFactory actually exists in the jar added by maven. Other dependencies added via maven (e.g. BoneCP) are found.

Pom.xml and web.xml are below.

<?xml version="1.0" encoding="UTF-8"?>
<project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <!-- POM file generated with GWT webAppCreator -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>my.group/groupId>
  <artifactId>artifact</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>ModuleName</name>

  <properties>
    <!-- Convenience property to set the GWT version -->
    <gwtVersion>2.5.0</gwtVersion>
    <!-- GWT needs at least java 1.5 -->
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>

    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>${gwtVersion}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>${gwtVersion}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
      <classifier>sources</classifier>
      <scope>test</scope>
    </dependency>

    <!-- mine -->
    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>3.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.gwt.inject</groupId>
        <artifactId>gin</artifactId>
        <version>2.1.2</version>
    </dependency>

    <dependency>
        <groupId>com.jolbox</groupId>
        <artifactId>bonecp</artifactId>
        <version>0.8.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.27</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>15.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava-gwt</artifactId>
        <version>15.0</version>
    </dependency>


  </dependencies>

  <build>
    <!-- Generate compiled stuff in the folder used for developing mode -->
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

    <plugins>

      <!-- GWT Maven Plugin -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>2.5.0</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <!--<goal>test</goal>-->
              <!--<goal>i18n</goal>-->
              <goal>generateAsync</goal>
            </goals>
          </execution>
        </executions>
        <!-- Plugin configuration. There are many available options, see 
          gwt-maven-plugin documentation at codehaus.org -->
        <configuration>
          <runTarget>ModuleName.html</runTarget>
          <hostedWebapp>${webappDirectory}</hostedWebapp>
          <!--<i18nMessagesBundle>my.group.artifact.client.Messages</i18nMessagesBundle>-->
        </configuration>
      </plugin>

      <!-- Copy static web files before executing gwt:run -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>exploded</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <webappDirectory>${webappDirectory}</webappDirectory>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

Relevant web.xml part

  <listener>
    <listener-class>
        my.group.artifact.server.MyServletContextListener
    </listener-class>
  </listener>

Entire stacktrace

[WARN] Server class 'com.mysql.jdbc.Driver' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/Documents%20and%20Settings/thomas/.m2/repository/mysql/mysql-connector-java/5.1.27/mysql-connector-java-5.1.27.jar' to the web app classpath for this session
   For additional info see: file:/C:/Documents%20and%20Settings/thomas/Desktop/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.5.1/gwt-2.5.1/doc/helpInfo/webAppClassPath.html
[WARN] Server class 'com.jolbox.bonecp.BoneCPConfig' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/Documents%20and%20Settings/thomas/.m2/repository/com/jolbox/bonecp/0.8.0.RELEASE/bonecp-0.8.0.RELEASE.jar' to the web app classpath for this session
   For additional info see: file:/C:/Documents%20and%20Settings/thomas/Desktop/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.5.1/gwt-2.5.1/doc/helpInfo/webAppClassPath.html
Starting Jetty on port 8888
   [WARN] failed com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload@12271e{/,/home/user/workspace\project\target\moduleName-0.0.1-SNAPSHOT}
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.jolbox.bonecp.BoneCPConfig.<clinit>(BoneCPConfig.java:62)
    at my.group.artifact.server.db.ConnectionPool.<init>(ConnectionPool.java:41)
    at my.group.artifact.server.db.ConnectionPool.getInstance(ConnectionPool.java:23)
    at my.group.artifact.server.MyServletContextListener.contextInitialized(MyServletContextListener.java:26)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
    at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1093)
    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:836)
    at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension.findClass(JettyLauncher.java:372)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:366)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
    ... 22 more
   [WARN] failed RequestLogHandler@19e9785
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.jolbox.bonecp.BoneCPConfig.<clinit>(BoneCPConfig.java:62)
    at my.group.artifact.server.db.ConnectionPool.<init>(ConnectionPool.java:41)
    at my.group.artifact.server.db.ConnectionPool.getInstance(ConnectionPool.java:23)
    at my.group.artifact.server.MyServletContextListener.contextInitialized(MyServletContextListener.java:26)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
    at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1093)
    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:836)
    at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension.findClass(JettyLauncher.java:372)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:366)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
    ... 22 more
   [WARN] Error starting handlers
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.jolbox.bonecp.BoneCPConfig.<clinit>(BoneCPConfig.java:62)
    at my.group.artifact.server.db.ConnectionPool.<init>(ConnectionPool.java:41)
    at my.group.artifact.server.db.ConnectionPool.getInstance(ConnectionPool.java:23)
    at my.group.artifact.server.MyServletContextListener.contextInitialized(MyServletContextListener.java:26)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
    at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1093)
    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:836)
    at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload$WebAppClassLoaderExtension.findClass(JettyLauncher.java:372)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:366)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
    ... 22 more
hansi
  • 2,278
  • 6
  • 34
  • 42

1 Answers1

1
[WARN] Server class 'com.mysql.jdbc.Driver' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/Documents%20and%20Settings/thomas/.m2/repository/mysql/mysql-connector-java/5.1.27/mysql-connector-java-5.1.27.jar' to the web app classpath for this session
   For additional info see: file:/C:/Documents%20and%20Settings/thomas/Desktop/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.5.1/gwt-2.5.1/doc/helpInfo/webAppClassPath.html
[WARN] Server class 'com.jolbox.bonecp.BoneCPConfig' could not be found in the web app, but was found on the system classpath
   [WARN] Adding classpath entry 'file:/C:/Documents%20and%20Settings/thomas/.m2/repository/com/jolbox/bonecp/0.8.0.RELEASE/bonecp-0.8.0.RELEASE.jar' to the web app classpath for this session
   For additional info see: file:/C:/Documents%20and%20Settings/thomas/Desktop/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.5.1/gwt-2.5.1/doc/helpInfo/webAppClassPath.html

This is the clue. The JARs should be loaded from the WEB-INF/lib, not from the classpath.

There are two things to notice here:

  • you're using Eclipse with the Google Plugin for Eclipse, but you're apparently not using M2Eclipse to import your Maven project into Eclipse (otherwise, the warning wouldn't have linked to the sdkbundle Eclipse plugin)
  • even if you were, you have to run mvn package once (and each time you change the classpath/buildpath) to copy all your dependencies to the WEB-INF/lib folder in the target/ so DevMode finds them where they're expected.
Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks for your help! Regarding your first point: You are right, I did not use M2Eclipse to import a maven project into Eclipse. First I created the Maven project via Eclipse's "New Maven Project" by selecting the `gwt-maven-plugin` archetype. Then I created the GWT source (that includes references to BoneCP and so on). But I don't understand what I should have done differently; How can I make the warning be linked to the sdkbundle Eclipse plugin? Second point: When I run `mvn package` the problem unfortunately persists. – hansi Dec 31 '13 at 02:14
  • 1
    The thing is: you shouldn't have a specific GWT entry in your build path; the GPE should automatically pick from the Maven dependencies. That way, you're sure to use the same GWT version in Eclipse as in your pom.xml, and it autoconfigures a few things that help running DevMode. Try re-importing the Maven project, or maybe just removing the GWT facet and then updating the project from Maven. Re. DevMode you should run it from your `target/${project.finalName}` folder, **not** from `src/main/webapp`. See http://stackoverflow.com/a/5745870/116472 (don't miss the comments on that answer) – Thomas Broyer Dec 31 '13 at 02:23
  • Just a note: Actually, what happens when I follow the second point: It is as you are saying - the dependencies are copies to `WEB-INF/lib`. But once I start Dev Mode the the lib folder is somehow removed. Will check your follow up suggestions. Thanks once again! – hansi Dec 31 '13 at 02:28
  • It works. Thanks a bunch. It looks like you were right: I created a new simple maven project without archetype. I dropped the sources and the pom I had from the project I had trouble with in it and then `mvn package` and works. I guess that means creating a maven project using the archetype `gwt-maven-plugin` doesn't produce a usable project. At least not for me. Before I tried to remove a GWT facet from the problematic project, but could not find a "GWT"-facet, only Java, JavaScript and Dynamic Web Project. Dev Mode ran from target/${project.finaleName}, so that was also not the problem. – hansi Dec 31 '13 at 04:14
  • You shouldn't use the gwt-maven-plugin archetype. This is an advice from a member of the GWT Steering Committee and de-facto lead-maintainer of the gwt-maven-plugin. The GWT team [doesn't recommend](https://code.google.com/p/google-web-toolkit/wiki/WorkingWithMaven#Sample_Projects) using it. – Thomas Broyer Dec 31 '13 at 04:18