Java JSON 包导入失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24714493/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:23:21  来源:igfitidea点击:

Java JSON package importing failure

javajsonpackage

提问by kernelbug

I'm working with OpenJDK 7 (openjdk-7-jdk) under Ubuntu, compiling my code with following command

我正在 Ubuntu 下使用 OpenJDK 7 (openjdk-7-jdk),使用以下命令编译我的代码

javac -d ./classes ./src/Program.java

My code contains imports

我的代码包含导入

...
import java.util.concurrent.ExecutorService;
import javax.json.Json;
import javax.json.stream.JsonParser;
import javax.swing.text.html.parser.ParserDelegator;
...

and i'm getting the following error

我收到以下错误

./src/Program.java:21: error: package javax.json does not exist
import javax.json.Json;
                 ^
./src/Program.java:22: error: package javax.json.stream does not exist
import javax.json.stream.JsonParser;
                        ^

It is curious that there is no problems with importing from javax.swing or java.util.

奇怪的是,从 javax.swing 或 java.util 导入都没有问题。

Please tell, what am i doing wrong?

请告诉,我做错了什么?

采纳答案by kernelbug

steps to follow:

要遵循的步骤:

  1. Download javax.json jar file.

  2. As you have downloaded this jar file, specify it in java compiler classpath, using javac -classpathkey.

  3. As you have your code compiled, then use -cpkey for javacommand to specify this jar file in the runtime classpath upon your code execution.

  1. 下载javax.json jar 文件

  2. 下载此 jar 文件后,请使用 javac-classpath键在 java 编译器类路径中指定它。

  3. 编译代码后,请在代码执行时使用-cpkey forjava命令在运行时类路径中指定此 jar 文件。

More detailed information on classpath settings can be found here: http://kevinboone.net/classpath.html

可以在此处找到有关类路径设置的更多详细信息:http: //kevinboone.net/classpath.html