【发布时间】:2018-08-22 08:48:29
【问题描述】:
我是第一次使用 Maven。
我想使用org.json,并且我已将依赖项添加到我的 pom.xml:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
</dependencies>
运行mvn package 工作正常。
尝试执行时,我收到以下错误消息:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
我尝试更改范围并仔细检查 API-documentation/xml-tags。
非常感谢任何帮助。
编辑:This answer 为我解决了这个问题 :-)
【问题讨论】:
-
如何打包您的应用程序?作为 JAR/WAR/EAR?你是如何运行你的代码的?
-
我把它打包成.jar。我正在使用 java -cp to/jar package.mainClass 在终端中运行。由这个答案解决:stackoverflow.com/a/10569417/8543529