java.lang.NoClassDefFoundError:在Netbeans IDE外部运行的org / json / simple / JSONObject

时间:2013-03-04 18:22:34

标签: java json netbeans

这里有关于此错误的类似问题,但我已经尝试了大多数解决方案并仍然得到相同的错误消息。我在我的java应用程序中使用json-simple库。我在我的库中包含了json-simple-1.1.1.jar文件。通过Netbeans运行完美。当我尝试通过命令行“java -jar”运行它时,我收到以下错误。甚至“java -cp json-simple-1.1.1.jar -jar仍然会给出相同的错误。

nullException in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/json/simple/JSONObject
    at gui.keo_synopticx.jb_save_configMouseClicked(keo_synopticx.java:5318)
    at gui.keo_synopticx.access$6000(keo_synopticx.java:49)
    at gui.keo_synopticx$60.mouseClicked(keo_synopticx.java:3358)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONObject
    at java.net.URLClassLoader$1.run(Unknown Source)

我可能错过了json-simple-1.1.1的依赖项?任何建议将不胜感激。

2 个答案:

答案 0 :(得分:1)

org / json / simple / JSONObject类肯定在jar文件中。

我能想到的问题的唯一原因是你没有指定jar文件路径,并且jar与执行目录不在同一目录中。

答案 1 :(得分:0)

要解决此问题,您应该在终端上确定您的类路径:

syntaxe:

java -classpath <your_archive.jar> [<package>.]<Class_name>

如果该类属于一个包,请不要忘记该包。