NoClassDefFoundError org/apache/cxf/jaxrs/client/WebClient

NoClassDefFoundError org/apache/cxf/jaxrs/client/WebClient

我是 CXF 网络服务的新手。我需要写一个休息客户端。我得到

 java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/client/WebClient
 com.test.ws.CXFWebServiceConnector.get(CXFWebServiceConnector.java:21)
 com.test.ws.SimpleServlet.doGet(SimpleServlet.java:29)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
 root cause

 java.lang.ClassNotFoundException: org.apache.cxf.jaxrs.client.WebClient
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
 com.test.ws.CXFWebServiceConnector.get(CXFWebServiceConnector.java:21)
 com.test.ws.SimpleServlet.doGet(SimpleServlet.java:29)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

这不是 Maven 项目。下面的罐子被添加到我的 class 路径中。要获得 NoClassDefinition 异常,我是否缺少任何其他库?

abdera-core-0.4.0-incubating.jar

abdera-extensions-main-0.4.0-incubating.jar

abdera-i18n-0.4.0-incubating.jar

abdera-parser-0.4.0-incubating.jar

公理-api-1.2.7.jar

axiom-impl-1.2.7.jar

cxf-2.2.6.jar

geronimo-activation-1.1.jar

geronimo-annotation-1.0.jar

jaxb-api-2.1.jar

jaxb-impl-2.1.12.jar

jra-1.0-alpha-4.jar

jsr311-api-1.0.jar

neethi-2.0.4.jar

wss4j-1.5.8.jar

wstx-asl-3.2.9.jar

xml-解析器-1.2.jar

XmlSchema-1.4.5.jar

这是我访问 Restful 网络服务的方式

public String get(String url) {
    String response = null;
    WebClient client = WebClient.create(url);
    client.accept(MediaType.APPLICATION_JSON);
    HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setAllowChunking(false);
    conduit.setClient(httpClientPolicy);
    TLSClientParameters clientParameters = new TLSClientParameters();
    clientParameters.setDisableCNCheck(true);
    clientParameters.setSecureSocketProtocol("TLS");
    conduit.setTlsClientParameters(clientParameters);
    try {
        response = client.get(String.class);

    } finally {
        if (client != null) {
            client.reset();
        }
    }

    return response;
}

WebClient 是 cxf-rt-frontend-jaxrs.jar 的一部分。我猜你没有 cxf JAXRS 相关的罐子。

在项目根目录中使用以下命令来检测需要哪些依赖项:

mvn dependency:tree -Dincludes=org.apache.cxf