从球衣 1.x 迁移到球衣 2.x ( 2.8 ) 时出现 NoClassDefFoundError ProcessingException

NoClassDefFoundError ProcessingException while migrating from jersey 1.x to jersey 2.x ( 2.8 )(从球衣 1.x 迁移到球衣 2.x ( 2.8 ) 时出现 NoClassDefFoundError ProcessingException)

本文介绍了从球衣 1.x 迁移到球衣 2.x ( 2.8 ) 时出现 NoClassDefFoundError ProcessingException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个 Web 服务应用程序,它在 jersey 1.x ( 1.16 ) 上运行良好我最近尝试迁移到最新的稳定球衣版本 2.8

I developed a web service application which was working fine with jersey 1.x ( 1.16 ) I recently tried to migrate to latest stable jersey version 2.8

我删除了 v1.16 的所有 jersey jar 文件然后我从链接下载了 v2.8 的球衣罐 - https://jersey.java.net/download.html

I deleted all jersey jar files of v1.16 then I downloaded jersey jars of v2.8 from the link - https://jersey.java.net/download.html

根据我了解到的文档,我应该有最新的 servlet jar,servlet jar 2.5 或更高版本,所以我下载了 servlet-api-2.5.jar 并将其添加到/libs 文件夹中.

As per documentation I came to know that, I should have latest servlet jar, servlet jar 2.5 or above, So I downloaded servlet-api-2.5.jar and added the same to /libs folder.

我下载了 javax.ws.rs-api-2.0-m09.jar 并将其添加到/libs我还将最新的 jettison v 1.3.3 添加到/libs

I downloaded javax.ws.rs-api-2.0-m09.jar and added it to /libs I also added latest jettison v 1.3.3 to /libs

但是当我在tomcat7上运行时出现异常,如下所示从 jersey 1.x 迁移到 2.x 的确切步骤是什么?这里缺少什么?

But I am getting exception when I run on tomcat7 as follows What are the exact steps to migrate from jersey 1.x to 2.x ? What is missing here ?

我的 Web.xml 如下所示

My Web.xml looks as follows

<?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" id="WebApp_ID" version="2.5">
  <display-name>com.tempWSJersey2.WebServices</display-name>
  <servlet>
    <servlet-name>Temp REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
     <param-name>jersey.config.server.provider.packages</param-name>
     <param-value>com.temp</param-value>
     </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Temp REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

例外是-

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/tempWSJersey2]]
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
    at java.util.concurrent.FutureTask.get(FutureTask.java:111)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/tempWSJersey2]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 7 more
Caused by: java.lang.NoClassDefFoundError: javax/ws/rs/ProcessingException
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2308)
    at java.lang.Class.getDeclaredFields(Class.java:1760)
    at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:87)
    at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:261)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:405)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.ProcessingException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    ... 28 more

May 11, 2014 8:49:41 AM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
    at java.util.concurrent.FutureTask.get(FutureTask.java:111)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:684)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:451)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more

May 11, 2014 8:49:41 AM org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:684)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:451)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 11 more

May 11, 2014 8:49:41 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1452 ms

如果我通过扩展 ResourceConfig 类来包含配置类我收到如下奇怪的错误.

If I include configuration class by extending ResourceConfig class I get strange error as follows.

Multiple markers at this line
    - The type javax.ws.rs.core.Configurable cannot be resolved. It is indirectly referenced 
     from required .class files
    - The hierarchy of the type AppConfiguration is inconsistent

更新 - 问题的解决方案1> 添加给定 jaxrs-ri 文件夹的所有 jar 文件,您从链接下载为 jersey 2.8
https://jersey.java.net/download.html

Update - Solution to the problem 1> Add all the jar files given jaxrs-ri folder which you download as jersey 2.8 from the link
https://jersey.java.net/download.html

从所有文件夹中添加jar文件,lib",ext",api"

Add jar files from all the folders , "lib", "ext", "api"

2> 添加下面帖子中列出的 jar 文件无法启用基于 POJOJersey 2.0 中对 Jackson 的 JSON 绑定支持

2> Add the jar files listed in the below post Can't enable POJO based JSON binding support for Jackson in Jersey 2.0

现在球衣 2.8 完美运行..

Now jersey 2.8 works perfectly ..

推荐答案

发生异常是因为您下载了 "javax.ws.rs-api-2.0-m09.jar" 这个 jar没有ProcessingException 下载最新的

Exception you are getting is happening because you downloaded "javax.ws.rs-api-2.0-m09.jar" this jar doesn't have ProcessingException download the latest one

Class not foundCaused by: java.lang.NoClassDefFoundError: javax/ws/rs/ProcessingException

下载这个jar javax.ws.rs-api-2.0.jar

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0</version>
</dependency>

其次,我认为您的 web.xml 缺少一部分

Secondly I think you are missing a part from your web.xml

尝试根据您的应用程序将这些内容添加到您的 web.xml 中.如果您没有此部分,这也可能导致 SEVERE: A child container failed during start....

Try adding these things to your web.xml as appropriate for you application. If you don't have this section this may also lead to SEVERE: A child container failed during start....

这就是你所缺少的.请注意,param-value 是包含您的休息服务的包的列表.

<servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages;org.codehaus.jackson.jaxrs</param-name>
        <param-value>com.your.package.for.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

要获取最新的 Jackson,请使用此 链接

<dependency>
    <groupId>com.fasterxml.jackson.jaxrs</groupId>
    <artifactId>jackson-jaxrs-json-provider</artifactId>
    <version>2.3.3</version>
</dependency>

这篇关于从球衣 1.x 迁移到球衣 2.x ( 2.8 ) 时出现 NoClassDefFoundError ProcessingException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:从球衣 1.x 迁移到球衣 2.x ( 2.8 ) 时出现 NoClassDefFoundError ProcessingException

基础教程推荐