简体   繁体   English

java.lang.ClassNotFoundException:用于org.json.simple.JSONObject

[英]java.lang.ClassNotFoundException: for org.json.simple.JSONObject

I have written a peiece of code that references a JSON library in my Eclipse. 我在Eclipse中编写了一个引用JSON库的代码。

When trying to Export to Jar file, I chose the option Export Java source files and resources . 尝试导出到Jar文件时,我选择了导出Java源文件和资源选项。

My code is dependent on JSONObject library. 我的代码取决于JSONObject库。

Now I have packaged all of my files and when I run the jar file on a linux machine, I get the ERROR:: 现在,我已经打包了所有文件,并且在Linux机器上运行jar文件时,出现错误:

# java -cp SendCommand.jar ExecuteShellComand
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONObject
    at ExecuteShellComand.main(ExecuteShellComand.java:19)
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONObject
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

Unzipping my jar file yields. 解压缩我的jar文件会产生结果。

# tree
.
├── commons-io-2.5.jar
├── ExecuteShellComand.class
├── ExecuteShellComand.java
├── json-simple-1.1.jar
├── SendCommand.jar
└── META-INF
    └── MANIFEST.MF

1 directory, 6 files

Although all the required files are present, I still get the ERROR. 尽管所有必需的文件都存在,但仍然出现错误。 What am I missing here ? 我在这里想念什么?

You need to separate out the json-simple-1.1.jar from SendCommand.jar . 您需要从SendCommand.jar分离出json-simple-1.1.jar

Instead copy json-simple-1.1.jar and other dependent JARs into your current directory so that you can confirm that executing the following modified command works: 而是将json-simple-1.1.jar和其他相关的JAR复制到当前目录中,以便您可以确认执行以下修改后的命令是否有效:

# java -cp SendCommand.jar:commons-io-2.5.jar:json-simple-1.1.jar ExecuteShellComand

Classpath reference: Right click on project in Eclipse -> Buildpath -> Configure Build path -> Java Build Path (left Pane) -> Libraries(Tab) -> Add External Jars -> Select your jar and select OK. 类路径参考:在Eclipse中的项目上单击鼠标右键->构建路径->配置构建路径-> Java构建路径(左窗格)->库(Tab)->添加外部Jars->选择您的jar并选择OK。

Deployment Assembly: Right click on WAR in eclipse-> Buildpath -> Configure Build path -> Deployment Assembly (left Pane) -> Add -> External file system -> Add -> Select your jar -> Add -> Finish. 部署程序集:右键单击Eclipse中的WAR->构建路径->配置构建路径->部署程序集(左窗格)->添加->外部文件系统->添加->选择jar->添加->完成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.String 不能转换为 org.json.simple.JSONObject simple-json - java.lang.String cannot be cast to org.json.simple.JSONObject simple-json java.lang.ClassNotFoundException: org.json.JSONObject - java.lang.ClassNotFoundException: org.json.JSONObject java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser - java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser 找不到org.json.simple.JSONObject - org.json.simple.JSONObject not found 我的Java Restful Web服务中的java.lang.ClassNotFoundException:org.json.JSONObject - java.lang.ClassNotFoundException: org.json.JSONObject in my java restful webservice java.lang.ClassCastException: 使用 java 读取 json 文件时,无法将 org.json.simple.JSONArray 转换为 org.json.simple.JSONObject 错误 - java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject error when reading json file iwith java 我想使用org.json.simple.JSONObject生成以下JSON数据对象,如何在Java中做到这一点? - I want to generate following JSON dataobject using org.json.simple.JSONObject, how to do it in java? java.lang.ClassNotFoundException: net.sf.json.JSONObject - java.lang.ClassNotFoundException: net.sf.json.JSONObject Servlet:java.lang.ClassNotFoundException:org.json.simple.parser.ParseException - Servlet: java.lang.ClassNotFoundException: org.json.simple.parser.ParseException 无法使用org.json.simple.JSONObject访问其余CXF - unable to access rest CXF with org.json.simple.JSONObject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM