简体   繁体   English

Restful webservices - NoClassDefFoundError:org / glassfish / jersey / ExtendedConfig

[英]Restful webservices - NoClassDefFoundError: org/glassfish/jersey/ExtendedConfig

So I created the webservice in this thread and finally I managed to solve the problem. 所以我在这个线程中创建了webservice,最后我设法解决了这个问题。 Now I'm trying to consume this webservice. 现在我正在尝试使用这个Web服务。

I've created a new web project on Netbeans and I'm using Apache Tomcat. 我在Netbeans上创建了一个新的Web项目,我正在使用Apache Tomcat。 Here's the code to consume the webservice. 这是使用Web服务的代码。 I've gone through some tutorials to produce this code. 我已经通过一些教程来生成这段代码。

package com.client;

import java.net.URI;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;

import org.glassfish.jersey.client.ClientConfig;

public class HelloClient {


  public void consumeRest(){

    ClientConfig config = new ClientConfig();

    Client client = ClientBuilder.newClient(config);

    WebTarget target = client.target(getBaseURI());

    System.out.println("response");

    System.out.println(target.path("hello").path("world").request()

    .accept(MediaType.APPLICATION_JSON).get(Response.class)

    .toString());

    }


  private URI getBaseURI() {

    return UriBuilder.fromUri("http://localhost:8084/restful_example").build();

  }

} 

I've created a main class to call the consume method. 我已经创建了一个主类来调用consume方法。 When I run it, I get this exception: 当我运行它时,我得到这个例外:

Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/jersey/ExtendedConfig
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    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 java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at com.client.HelloClient.consumeRest(HelloClient.java:29)
    at com.client.main.main(main.java:16)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.ExtendedConfig
    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 java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 14 more
Java Result: 1

I guess it's a libs problem but I couldn't solve it. 我想这是一个libs问题,但我无法解决它。 Using only JAX-RS 2.0 is not sufficient, so I'm also using Jersey libs. 仅使用JAX-RS 2.0是不够的,所以我也使用Jersey libs。

What's wrong here? 这有什么不对? Is this the correct way to consume this webservice? 这是使用此Web服务的正确方法吗? I've seen some other versions and I'm not sure which one to use. 我见过其他一些版本,我不确定使用哪一个版本。

Seems that you are missing the jersey-common jar from your classpath 似乎你错过了类路径中的jersey-common jar

You can download the jar on maven at the following url : - http://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-common 您可以在以下网址下载maven上的jar: - http://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-common

As I suspected, it was a libs problem. 我怀疑,这是一个库存问题。 This code and these imports work only with Jersey 2.X (it's on version 2.17 as of today). 此代码和这些导入仅适用于Jersey 2.X(截至今日版本为2.17)。 I needed to include all the libs in the bundle, ie, all the core Jersey module jars as well as all the required 3rd-party dependencies. 我需要在bundle中包含所有lib,即所有核心Jersey模块jar以及所有必需的第三方依赖项。 I don't need to include any JAX-RS 2.0 libs or Jersey 1.X jars. 我不需要包含任何JAX-RS 2.0库或Jersey 1.X罐。

Another thing I did was using the New RESTful Java Client wizard in Netbeans and then adding the Jersey 1.X jars to my project (it's on version 1.19 as of today). 我做的另一件事是在Netbeans中使用New RESTful Java Client向导,然后将Jersey 1.X罐子添加到我的项目中(截至今天版本为1.19)。 The API is a little different but works as well. API有点不同但也可以使用。

To remove the particular message: 要删除特定邮件:

NoClassDefFoundError: org/glassfish/jersey/ExtendedConfig

Try to include the correct version of jersey-common.jar into the lib folder of your application. 尝试将正确版本的jersey-common.jar包含到应用程序的lib文件夹中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NoClassDefFoundError:org / glassfish / jersey / process / internal / RequestExecutorFactory - NoClassDefFoundError: org/glassfish/jersey/process/internal/RequestExecutorFactory 泽西岛客户端文件上传异常:NoClassDefFoundError:org / glassfish / jersey / message / internal / HeadersFactory - Jersey client file upload exception: NoClassDefFoundError: org/glassfish/jersey/message/internal/HeadersFactory Tomcat + Jersey产生org.glassfish.jersey.server.ContainerException:java.lang.NoClassDefFoundError - Tomcat + Jersey produces org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError org.glassfish.jersey.server.ContainerException:java.lang.NoClassDefFoundError:org.testng.TestNG? - org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org.testng.TestNG? java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder 启动 Tomcat 服务器时 - java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder when started Tomcat Server 需要添加什么依赖项以避免 java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/guava/Sets? - What dependency needs to be added to avoid java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/guava/Sets? 引起:java.lang.NoClassDefFoundError:org/glassfish/jersey/server/model/Parameter$Source - Caused by: java.lang.NoClassDefFoundError: org/glassfish/jersey/server/model/Parameter$Source 获取错误:org.glassfish.jersey.server.ContainerException:java.lang.NoClassDefFoundError:javax/validation/ValidatorFactory - Getting error : org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: javax/validation/ValidatorFactory 引起:java.lang.NoClassDefFoundError: org/glassfish/jersey/jackson/internal/jackson/jaxrs/cfg/ObjectWriterModifier - Caused by: java.lang.NoClassDefFoundError: org/glassfish/jersey/jackson/internal/jackson/jaxrs/cfg/ObjectWriterModifier 带有jersey和tomcat的静态Web服务错误:404 - Restful webservices with jersey and tomcat error: 404
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM