Jersey ClientBuilder.newClient():找不到源 [英] Jersey ClientBuilder.newClient(): source not found

查看:1285
本文介绍了Jersey ClientBuilder.newClient():找不到源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java 64位Eclipse应用程序,其中Eclipse在Windows 7 Pro x64上运行。

I have an Java 64-bit Eclipse application with Eclipse running on Windows 7 Pro x64.

我下载了 Jersey bundle,jaxrs-ri-2.7.zip,用于客户端RESTful API访问。

I downloaded the Jersey bundle, jaxrs-ri-2.7.zip, for client RESTful API access.

我添加了这些外部jar(项目|构建路径|配置构建路径... |库):

I added these external jars (Project | Build Path | Configure Build Path... | Libraries):

jaxrs-ri/api/javax.ws.rs-api-2.0.jar
jaxrs-ri/lib/jersey-client.jar
jaxrs-ri/lib/jersey-common.jar

以下是来源:

package prjTestJersey;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

public static void main(String[] args)
{
    try
    {
        Client oClient = ClientBuilder.newClient();

        oClient.close();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

我踩到第一个时收到以下错误line,Clinet oClient ...:

I receive the following error, when stepping over the first line, Clinet oClient...:

Source not found.

为什么错误以及如何解决?为什么找不到源而不是真正的错误。

Why the error and how do I fix it? Why "source not found" instead of a real error.

注意:我尝试将3个jar文件复制到项目的lib文件夹中,但这没有任何好处。我正在使用Eclipse调试器,所以在调试视图中按F11,然后在线上执行F6。

Note: I tried copying the 3 jar files to the project's lib folder, but that did not do any good. I am using the Eclipse debugger, so pressing F11 in debug view and then doing an F6 over the line.

更新:

我尝试创建一个全新的32位应用程序(WindowBuilder SWT应用程序窗口)并简单地更新main(...),同样的问题。这意味着该问题与平台无关。

I tried creating a brand new 32-bit application (WindowBuilder SWT application window) and simply updated main(...), and same problem. That means the problem is platform independent.

更新2:

尝试运行的已发布答案不是馊主意。 :-)这给了另一条线索,我必须追查。这是转储。

The posted answer to try running was not a bad idea. :-) That gave another clue, which I have to track down. Here is the dump.

Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/hk2/utilities/binding/AbstractBinder
    at org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:452)
    at org.glassfish.jersey.client.JerseyClientBuilder.<init>(JerseyClientBuilder.java:94)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:116)
    at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:206)
    at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
    at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
    at AppMain.main(AppMain.java:20)
Caused by: java.lang.ClassNotFoundException: org.glassfish.hk2.utilities.binding.AbstractBinder
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 12 more

最终答案:
(感谢帮助的答案。)

FINAL ANSWER: (Thanks to both answers for the help.)

我缺少依赖项。需要的清单是:

I was missing dependencies. The needed list is:

swt_win32_x86.jar
api/javax.ws.rs-api-2.0.jar
ext/jersey-guava-2.7.jar
ext/hk2-api-2.2.0.jar
lib/jersey-common.jar
lib/jersey-client.jar


推荐答案

我的猜测是找不到来源只是一个来自Eclipse的消息告诉你它无法调试到客户端oClient = ClientBuilder.newClient(); ,因为你没有Eclipse中附加的三个jar的源代码。如果你只是运行程序(没有调试)它可能会很好地工作。在这里阅读更多关于如何在Eclipse中向jar文件添加源代码的内容:是否有一种简单的方法可以在Eclipse中附加源代码?

My guess is that "Source not found" simply is a message from Eclipse telling you it cannot debug into Client oClient = ClientBuilder.newClient(); as you do not have the source code for the three jars attached in Eclipse. If you just run the program (without debugging) it might very well work. Read more here on how to add source code to jar files in Eclipse: Is there an easy way to attach source in Eclipse?.

如果它仍然不起作用,我建议你从你下载的软件包中添加所有罐子,以确保你没有丢失一些依赖。

If it still doesn't work, I would suggest adding all the jars from the bundle you downloaded to make sure you aren't missing some dependency.

这篇关于Jersey ClientBuilder.newClient():找不到源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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