[英]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.