如何在 Eclipse 中导入 javax.json
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18346609/
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
How can I import javax.json in eclipse
提问by user1876508
I have installed eclipse ide for EE developers and I am receiving an import error for
我已经为 EE 开发人员安装了 eclipse ide,我收到了一个导入错误
import javax.json.Json;
import javax.json.JsonReader;
etc.
I have right clicked on project folder -> clicked properties -> clicked Java build path -> add library -> JRE System Library,
我右键单击项目文件夹 -> 单击属性 -> 单击 Java 构建路径 -> 添加库 -> JRE 系统库,
but the dependencies that show up are already imported. How can I import the javax.json package?
但显示的依赖项已经导入。如何导入 javax.json 包?
采纳答案by user2601995
If using Maven, add this dependencyto your pom.xml
如果使用 Maven,请将此依赖项添加到您的pom.xml
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
</dependency>
For Gradle, add this to your build.gradle
对于 Gradle,将此添加到您的 build.gradle
compile 'javax.json:javax.json-api:1.0'
回答by Mehul Rathod
You will have to download the Jar from https://java.net/projects/jsonp/as they are not yet part of main Java runtime, download the jar and add it to your classpath and it should work
您必须从https://java.net/projects/jsonp/下载 Jar,因为它们还不是主要 Java 运行时的一部分,下载 jar 并将其添加到您的类路径中,它应该可以工作
回答by Mark R
You need to get a hold of the Jar from https://java.net/projects/jsonp/
您需要从https://java.net/projects/jsonp/获取 Jar
Then got to project folder -> clicked properties -> clicked Java build path -> Add External Jars...
然后进入项目文件夹->单击属性->单击Java构建路径->添加外部罐子...
From here you can import the downloaded Jar (library) into your project.
从这里您可以将下载的 Jar(库)导入到您的项目中。
回答by dispake
Going to assume that you are not using Java 7 and thus need to add the JAR file directly to your project path:
假设您没有使用 Java 7,因此需要将 JAR 文件直接添加到您的项目路径中:
Here's the link to the JAR
这是JAR的链接
And where it came from: http://jsonp.java.net/
它来自哪里:http: //jsonp.java.net/
Download and add to your project build path.
下载并添加到您的项目构建路径。
回答by yper
Using javax.json
group (what is in the accepted version) doesn't work for me. I get this:
使用javax.json
组(已接受版本中的内容)对我不起作用。我明白了:
javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found
Instead, what does work for me is the following (put this in the dependencies
section of build.gradle
if you're using Gradle):
相反,对我有用的是以下内容(如果您正在使用 Gradle dependencies
,build.gradle
请将其放在部分):
implementation "org.glassfish:javax.json:1.1.4"
To find the latest version of the library, see the library's search.maven.org page.
要查找库的最新版本,请参阅库的 search.maven.org 页面。