宁静的Web服务-NoClassDefFoundError:org/glassfish/jersey/ExtendedConfig [英] Restful webservices - NoClassDefFoundError: org/glassfish/jersey/ExtendedConfig

查看:298
本文介绍了宁静的Web服务-NoClassDefFoundError:org/glassfish/jersey/ExtendedConfig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在 this中创建了Web服务线程,最后我设法解决了这个问题.现在,我正在尝试使用此Web服务.

So I created the webservice in this thread and finally I managed to solve the problem. Now I'm trying to consume this webservice.

我已经在Netbeans上创建了一个新的Web项目,并且正在使用Apache Tomcat.这是使用Web服务的代码.我已经看过一些教程来生成此代码.

I've created a new web project on Netbeans and I'm using Apache Tomcat. Here's the code to consume the webservice. 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();

  }

} 

我已经创建了一个主类来调用consume方法.运行它时,出现此异常:

I've created a main class to call the consume method. 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

我想这是一个库问题,但我无法解决.仅使用JAX-RS 2.0是不够的,所以我也使用Jersey的库.

I guess it's a libs problem but I couldn't solve it. Using only JAX-RS 2.0 is not sufficient, so I'm also using Jersey libs.

这是怎么了?这是使用此Web服务的正确方法吗?我看过其他一些版本,不确定使用哪个版本.

What's wrong here? Is this the correct way to consume this webservice? I've seen some other versions and I'm not sure which one to use.

推荐答案

我怀疑这是一个libs问题.此代码和这些导入仅适用于Jersey 2.X(截止到今天,版本为2.17).我需要在捆绑包中包含所有库,即所有核心Jersey模块jar以及所有必需的3rd-party依赖关系.我不需要包含任何JAX-RS 2.0库或Jersey 1.X jar.

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). 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. I don't need to include any JAX-RS 2.0 libs or Jersey 1.X jars.

我做的另一件事是在Netbeans中使用New RESTful Java Client向导,然后将Jersey 1.X jar添加到我的项目中(到目前为止,它的版本为1.19).该API稍有不同,但也可以正常工作.

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). The API is a little different but works as well.

这篇关于宁静的Web服务-NoClassDefFoundError:org/glassfish/jersey/ExtendedConfig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆