我试图访问网络服务(文档:http://docs.bittpublic.apiary.io/#reference/public-http-api/ticker/gets-the-current-ticker-data-for-a-given-currency-pair)。我需要从这个JSON,字段"卷"中获取信息。从回应。但我在客户端构建器中遇到问题。检查我的代码/错误:
代码:
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
Client client = ClientBuilder.newClient();
Entity payload = Entity.json("{ 'productPair': 'BTCUSD'}");
Response response = client.target("https://api.bitt.com:8400")
.path("/ajax/v1/GetTicker")
.request(MediaType.APPLICATION_JSON_TYPE)
.post(payload);
System.out.println("status: " + response.toString());
错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/util/collection/UnsafeValue
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2663)
at java.lang.Class.getConstructor0(Class.java:3067)
at java.lang.Class.newInstance(Class.java:408)
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:118)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:225)
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
at exchanges.barbados.Bitt.getTicker(Bitt.java:72)
at exchanges.barbados.Bitt.get24hrVol(Bitt.java:59)
at exchanges.barbados.Bitt.<init>(Bitt.java:51)
at main.Main.main(Main.java:363)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.util.collection.UnsafeValue
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 12 more
Java Result: 1
我不知道什么是org / glassfish / jersey / internal / util / collection / UnsafeValue,我在网上找到的所有信息都是关于将一个webservice放到网上,而不是访问它。
我添加的罐子:
javax.ws.rs-API-2.0.1.jar
Jersey的客户端 - 2.17.jar
答案 0 :(得分:5)
你需要jersey-common-2.17.jar。你可以从这里得到它:http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.glassfish.jersey.core%22
每当你在第三方类上获得NoClassDefFoundError或ClassNotFoundException时,你可以通过谷歌类名来找出它应该在哪个jar文件中。