Java 导入 org.json.JSONObject 时包 org.json 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24236749/
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
package org.json does not exist when importing org.json.JSONObject
提问by ant2009
I am using:
我在用:
- emacs 24.3.1
- Fedora 20
- jdk1.7.0_45
- Emacs 24.3.1
- 软呢帽 20
- jdk1.7.0_45
I have created a Java project using emacs and have the following project and classpath files:
我使用 emacs 创建了一个 Java 项目,并具有以下项目和类路径文件:
.project
。项目
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>snaprequest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
.classpath
.classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
I have this version
我有这个版本
In my Java program I want to use the JSONObject so I tried to import the following:
在我的 Java 程序中,我想使用 JSONObject,所以我尝试导入以下内容:
import org.json.JSONObject;
And when I try and compile on the command line I get this error:
当我尝试在命令行上编译时,出现此错误:
error: package org.json does not exist
import org.json.JSONObject;
I know I need to add something on my classpath so it can find the jar files, but I am not sure how?
我知道我需要在我的类路径上添加一些东西,以便它可以找到 jar 文件,但我不确定如何?
采纳答案by Atul Kumbhar
Class org.json.JSONObject is available in json-20131018.jar. You need to download this jar and add this jar to your buildpath.
类 org.json.JSONObject 在 json-20131018.jar 中可用。您需要下载此 jar 并将此 jar 添加到您的构建路径中。
In order to add external jar to buildpath you can - right click on your project in eclipse - click build path -> configure build path - goto tab libraries - there you will find to add external JAR
为了将外部 jar 添加到构建路径,您可以 - 在 eclipse 中右键单击您的项目 - 单击构建路径 -> 配置构建路径 - 转到选项卡库 - 在那里你会发现添加外部 JAR
This will allow you to include any external jar into your build path.
这将允许您将任何外部 jar 包含到您的构建路径中。