现在已经在这一天了。我有一个java servlet,使用maven构建,将部署到Jetty(旧版本)。这是一个使用RESTEasy和Jackson构建的Jetty上的RESTful Web服务,以及将我连接到MongoDB的Jackson Mongo Mapper。
我可以很好地运行maven / jetty中的应用程序(使用mvn jetty:run),并且对于不使用Jackson Mongo Mapper / Jackson位的查询,它会按预期返回JSON。当我发送触发杰克逊和映射器的请求时,我首先得到这个错误:
java.lang.NoClassDefFoundError: org/codehaus/jackson/map/deser/std/StdDeserializer
当我第二次提交(以及所有后续请求)时,我收到此错误:
java.lang.NoClassDefFoundError: Could not initialize class net.vz.mongodb.jackson.JacksonDBCollection
就我所知,我已经正确设置了所有依赖项,尽管我会在问题的最后包含我的web.xml和pom.xml。如果它不是依赖项,那么我可能会遇到一些关于我的bean(BillItem.class)如何通过的问题。我对Java比较陌生,所以这很容易成为一个愚蠢的错误,而不是与我正在尝试实现的特定堆栈有关的东西...对于发生了什么的任何想法?
这是我的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>
这是我的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>
以下的最后一行是引发错误的违规电话:
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);
答案 0 :(得分:0)
这是一些严重的白痴。当我清理我的pom文件时,我不小心删除了3个jackson依赖项。