java—如何正确设置jaxrs客户机依赖关系?

ehxuflar  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(203)

我正在尝试将jax rs 2.0用于现有的java客户机代码(java 8),它以前不支持maven(我不想使用maven或任何类似的框架),但是jax rs“客户机”需要org.glassfish.jersy.client的依赖性,所以我出去阅读了关于一般依赖性和我刚接触的框架的内容。
将maven framework添加到我的项目中,并编辑了pom.xml文件中的依赖项:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>CVT Sale Data Manager</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersy.bundles</groupId>
            <artifactId>jaxrs-ri</artifactId>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersy.media</groupId>
            <artifactId>jersy-media-moxy</artifactId>
        </dependency>
    </dependencies>

</project>

这是restapi代码的一部分:

package api;

import javax.ws.rs.client.*;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

public class RestApi {

    private static Client client;
    private static WebTarget baseTarget;            //base url

    public RestApi()
    {
        //changed on the server
        ClientBuilder.newBuilder().build();
        client = ClientBuilder.newClient();

        baseTarget = client.target("http://127.0.0.1:8000/api");
        client = ClientBuilder.newClient();
    }

不知怎的,我还是犯了同样的错误:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
    at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
    at api.RestApi.<init>(RestApi.java:27)
    at Launcher.initSingeltons(Launcher.java:36)
    at Launcher.main(Launcher.java:29)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:87)
    at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:185)
    at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:70)
    ... 14 more
Exception running application Launcher

我是非常新的这些依赖类型的事情,所以它很可能是我有一个非常明显的错误,我不知道,我事先道歉,如果是这样的情况。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题