在 javax.json.spi.JsonProvider.provider(JsonProvider.java:97) 中找不到提供程序 org.glassfish.json.JsonProviderImpl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47022653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Provider org.glassfish.json.JsonProviderImpl not found at javax.json.spi.JsonProvider.provider(JsonProvider.java:97)
提问by Shaurya Manhar
How to run Java API for JSON Processing(JSR 374) in eclipse?
I am trying to parse JSON string to JsonParser(javax.json.stream.JsonParser). Also added javax.json-api-1.0.jar in the build path. At runtime, there is an exception.
My code is
如何在 Eclipse 中为 JSON 处理(JSR 374)运行 Java API?
我正在尝试将 JSON 字符串解析为 JsonParser(javax.json.stream.JsonParser)。还在构建路径中添加了 javax.json-api-1.0.jar。在运行时,有一个例外。我的代码是
import java.io.StringReader;
import javax.json.Json;
import javax.json.JsonReader;
import javax.json.JsonStructure;
import javax.json.stream.JsonParser;
import javax.json.stream.JsonParser.Event;
import javax.json.JsonReader;
import javax.json.JsonStructure;
import javax.json.stream.JsonParser;
import javax.json.stream.JsonParser.Event;
public class jsonnn {
public class jsonnn {
public static void main(String[] args) {
// Parse back
final String result = "{\"name\":\"Falco\",\"age\":3,\"bitable\":false}";
final JsonParser parser = Json.createParser(new StringReader(result));
String key = null;
String value = null;
while (parser.hasNext()) {
final Event event = parser.next();
switch (event) {
case KEY_NAME:
key = parser.getString();
System.out.println(key);
break;
case VALUE_STRING:
value = parser.getString();
System.out.println(value);
break;
}
}
parser.close();
}
}
And the exception is
例外是
Exception in thread "main" javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found
at javax.json.spi.JsonProvider.provider(JsonProvider.java:97)
at javax.json.Json.createParser(Json.java:90)
at jsonnn.main(jsonnn.java:14)
Caused by: java.lang.ClassNotFoundException: org.glassfish.json.JsonProviderImpl
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javax.json.spi.JsonProvider.provider(JsonProvider.java:94)
... 2 more
回答by Mike
You're developing against an API and have no implementation for that API. You need to make sure you have an implementation of the JSON-P specification to actually run the code you're trying to use.
您正在针对 API 进行开发,并且没有针对该 API 的实现。您需要确保拥有 JSON-P 规范的实现才能实际运行您尝试使用的代码。
In the JSR 374 official website Getting Started guide, it shows that you need twoMaven dependencies - one for the API and one for the reference implementation - before you can use JSON-P 1.1:
在JSR 374 官网 Getting Started guide 中,它显示您需要两个Maven 依赖项 - 一个用于 API,一个用于参考实现 - 才能使用 JSON-P 1.1:
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1</version>
</dependency>
Since it looks like you're not using Maven, you will need to download the implementation JAR from Maven Central manually: https://repo1.maven.org/maven2/org/glassfish/javax.json/1.1/
由于看起来您没有使用 Maven,因此您需要手动从 Maven Central 下载实现 JAR:https: //repo1.maven.org/maven2/org/glassfish/javax.json/1.1/
Or just click this direct link to download the JAR: javax.json-1.1.jar
或者只需单击此直接链接即可下载 JAR:javax.json-1.1.jar