Java JSON包导入失败 [英] Java JSON package importing failure

查看:543
本文介绍了Java JSON包导入失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我的代码包含导入

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

我遇到以下错误

./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;
                        ^

很好奇,从javax.swing或java.util导入没有问题.

请告诉我,我在做什么错了?

解决方案

要遵循的步骤:

  1. 下载 javax.json jar文件.

  2. p>
  3. 下载此jar文件后,请使用javac -classpath键在Java编译器类路径中指定该文件.

  4. 在编译代码后,使用-cp键输入java命令,以便在执行代码时在运行时类路径中指定此jar文件.

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

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

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.

Please tell, what am i doing wrong?

解决方案

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 -classpath key.

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

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

这篇关于Java JSON包导入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆