mavenservletsjacksonresteasymongo-jackson-mapper

Errors while calling mongo-jackson mapper from RESTEasy method


Been on this one for a few days now. I have a java servlet, built with maven that will be deployed to Jetty (an older version). It's a RESTful web service on Jetty built with RESTEasy and Jackson, and the Jackson Mongo Mapper to connect me to MongoDB.

I can run the application from maven/jetty just fine (using mvn jetty:run), and it returns JSON as expected for queries that don't use the Jackson Mongo Mapper/Jackson bit. When I send a request that triggers Jackson and the mapper, however, I first get this error:

java.lang.NoClassDefFoundError: org/codehaus/jackson/map/deser/std/StdDeserializer

When I submit a second time (and all subsequent requests), I get this error:

java.lang.NoClassDefFoundError: Could not initialize class net.vz.mongodb.jackson.JacksonDBCollection

As nearly as I can tell, I have all the dependencies set up correctly, although I'll include my web.xml and pom.xml at the end of the question. If it isn't a dependency, it's occurred to me that there might be some issue with how my bean (BillItem.class) is getting passed. I'm relatively new to Java so this could easily be a stupid mistake rather than something related to the specific stack I'm trying to implement...any ideas of what is going on?

Here's my web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

   <welcome-file-list>
    <welcome-file>index.html</welcome-file>
   </welcome-file-list>

   <!--  
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>     
    </context-param> -->

   <context-param>
        <param-name>resteasy.resources</param-name>
        <param-value>com.myproject.BillServer</param-value>
   </context-param>

   <context-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>com.myproject.Service</param-value>
   </context-param>

    <context-param>
      <param-name>resteasy.resource.method-interceptors</param-name>
      <param-value>org.jboss.resteasy.core.ResourceMethodSecurityInterceptor</param-value>
   </context-param>

   <listener>
      <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
   </listener>

    <servlet>     
      <servlet-name>Resteasy</servlet-name>
      <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
      <servlet-name>Resteasy</servlet-name>
      <url-pattern>/*</url-pattern>
   </servlet-mapping>

</web-app>

Here's my pom.xml:

<?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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myproject</groupId>
    <version>0.0.1-SNAPSHOT</version>
    <name>MyProject</name>
    <artifactId>MyProject</artifactId>
    <packaging>jar</packaging>

    <properties>
        <java.version>1.6</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>


    <dependencies>
        <!-- Servlet API -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <!-- Jetty -->
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-webapp</artifactId>
            <version>8.1.7.v20120910</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jsp-2.1-glassfish</artifactId>
            <version>2.1.v20100127</version>
        </dependency>   

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson-provider</artifactId>
            <version>2.3.4.Final</version>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>2.3.4.Final</version>    
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>jaxrs-api</artifactId>
            <version>2.3.4.Final</version>
          </dependency>
          <dependency>
              <groupId>org.codehaus.jackson</groupId>
              <artifactId>jackson-core-asl</artifactId>
              <version>1.9.9</version>
          </dependency>
          <dependency>
              <groupId>net.vz.mongodb.jackson</groupId>
              <artifactId>mongo-jackson-mapper</artifactId>
              <version>1.4.2</version>
          </dependency>       
          <dependency>
              <groupId>org.mongodb</groupId>
              <artifactId>mongo-java-driver</artifactId>
              <version>2.9.1</version>
          </dependency>
    </dependencies>

    <build>
        <plugins>

            <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

            <!-- The maven app assembler plugin will generate a script that sets up the classpath and runs your project -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>1.1.1</version>
                <configuration>
                    <assembleDirectory>target</assembleDirectory> 
                    <programs>
                        <program>
                            <mainClass>com.MyProject.Main</mainClass>
                            <name>webapp</name>
                        </program>
                    </programs>
                    <useAllProjectDependencies>true</useAllProjectDependencies>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                    </execution>                
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

And the last line of the following is the offending call that's throwing the error:

        Mongo mongo = new Mongo(MONGO_PATH, MONGO_PORT);
        DB db = mongo.getDB(MONGO_APPDB);
        DBCollection collection = db.getCollection(MONGO_BILL_COL);
        JacksonDBCollection<BillItem, String> coll = JacksonDBCollection.wrap(collection, BillItem.class, String.class);

Solution

  • This was some serious idiocy. I accidentally deleted 3 of the jackson dependencies when I was cleaning up my pom file.