使用Jersey和Moxi的Java中的NoClassDef异常

时间:2014-04-15 07:21:23

标签: java json jersey tomcat7

我是泽西的新手,我得到了应用程序并且正在运行,但是当我尝试使用moxy进行Json处理时,我遇到了问题。我克服了几个问题。添加这两个JARS之后没有:

  • Jersey的媒体MOXY-2.7
  • jersey-entity-filtering-2.3

我收到以下错误:

    Apr 15, 2014 10:20:34 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet jersey-serlvet
java.lang.NoClassDefFoundError: org/glassfish/jersey/moxy/json/internal/ConfigurableMoxyJsonProvider
    at org.glassfish.jersey.moxy.json.MoxyJsonFeature.configure(MoxyJsonFeature.java:79)
    at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:680)
    at org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:610)
    at org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:800)
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:385)
    at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:162)
    at org.glassfish.jersey.server.ApplicationHandler$3.run(ApplicationHandler.java:322)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:319)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:284)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:168)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

非常感谢您的帮助。我没有使用maven或任何其他构建或依赖工具。

4 个答案:

答案 0 :(得分:0)

解决!

我使用Json处理api jsonp。在我的代码中,我正在处理&#34;低级&#34;莫西不支持低级别。

答案 1 :(得分:0)

我在使用泽西时遇到了同样的问题,我只是将版本更改为 <jersey.version>2.15</jersey.version>它可以工作,我使用这个依赖项

        <dependency>
          <groupId>org.glassfish.jersey.ext</groupId>
          <artifactId>jersey-entity-filtering</artifactId>
          <version>2.15</version>
        </dependency>
        <dependency>
           <groupId>org.glassfish.jersey.media</groupId>
           <artifactId>jersey-media-moxy</artifactId>
           <version>2.15</version>
        </dependency>

它对我有用

答案 2 :(得分:0)

解决了,我有同样的问题,这对我有用。

<dependency>
   <groupId>org.glassfish.jersey.media</groupId>
   <artifactId>jersey-media-moxy</artifactId>
   <version>2.8</version>
</dependency>

Jersey REST API: java.lang.NoSuchMethodError: org.glassfish.jersey.message.filtering.EntityFilteringFeature.enabled

答案 3 :(得分:0)

添加这些依赖项解决了我的问题。

*"org.glassfish.jersey.media:jersey-media-json-jackson:2.25.1",
"com.fasterxml.jackson.module:jackson-module-jaxb-annotations:$versionJackson",
"com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.8.9",
"com.fasterxml.jackson.core:jackson-databind:$versionJackson",
"com.fasterxml.jackson.core:jackson-annotations:$versionJackson",
"com.fasterxml.jackson.core:jackson-core:$versionJackson",
"com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:$versionJackson",
"org.glassfish.jersey.ext:jersey-entity-filtering:2.15" *


versionJackson = "2.8.9"