JSONObject ClassNotFoundException [英] JSONObject ClassNotFoundException
问题描述
我在IntelliJ工作并使用maven。我有一个使用JSONObject的类,我已导入它
I am working in IntelliJ and using maven. I have a class that uses JSONObject, and I have imported it
import org.json.JSONObject;
在我使用它的方法中如下:
and in a method I use it like so:
JSONObject documentObj = null;
try {
documentObj = new JSONObject(document);
} catch (Exception e) {
throw new RuntimeException("Failed to convert JSON String document into a JSON Object.", e);
}
我在pom.xml文件中也有依赖
I also have the dependency in the pom.xml file
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
我可以mvn clean package这段代码,所有内容都成功构建。但是当我尝试运行它时,我得到Error:java.lang.ClassNotFoundException:org.json.JSONObject。
I can "mvn clean package" this code and everything builds successfully. But when I try to run it, I get "Error: java.lang.ClassNotFoundException: org.json.JSONObject".
这里还有什么我想念的吗?
Is there anything else I'm missing here?
谢谢!
推荐答案
添加json jar 到您的类路径
或使用 java -classpath json.jar ClassName
或者将此添加到你的maven pom.xml依赖项中:
Or add this to your maven pom.xml depedencies:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
这篇关于JSONObject ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!