java.lang.NoClassDefFoundError:jakarta/ws/rs/client/ClientBuilder

问题描述 投票:0回答:1

我为 JAX-RS Java 应用程序编写了一个客户端类。我使用 Jakarta EE 9 和 Glassfish 作为应用程序服务器。问题是,当我运行这个类时,出现以下错误。

Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/ws/rs/client/ClientBuilder
    at com.example.restaurantrest.ManagerClient.main(ManagerClient.java:13)
Caused by: java.lang.ClassNotFoundException: jakarta.ws.rs.client.ClientBuilder
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 1 more

这就是班级

package com.example.restaurantrest;

import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;

public class ManagerClient {

    public static void main(String[] args) {
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target("http://localhost:8080/RestaurantREST-1.0-SNAPSHOT/restaurant/reservations");
        Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_XML);

        //...

    }
}

这些是我的 pom.xml 文件的依赖项

    <dependencies>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>jakarta.enterprise</groupId>
            <artifactId>jakarta.enterprise.cdi-api</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakata.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>5.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>3.1.0</version>
        </dependency>
    </dependencies>

我尝试在 pom.xml 中使用不同的依赖项,但没有一个起作用。

java jakarta-ee jersey glassfish jax-rs
1个回答
0
投票

有关如何解决此问题的任何更新吗?

© www.soinside.com 2019 - 2024. All rights reserved.