问题描述
我正在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导入没有问题.
请告诉我,我在做什么错了?
要遵循的步骤:
-
下载 javax.json jar文件.
p> -
下载此jar文件后,请使用javac
-classpath
键在Java编译器类路径中指定该文件. -
在编译代码后,使用
-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:
Download javax.json jar file.
As you have downloaded this jar file, specify it in java compiler classpath, using javac
-classpath
key.As you have your code compiled, then use
-cp
key forjava
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包导入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!