Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
Asked Answered
B

3

5

I'm using org.json.JSONObject to pass the parameters to the server. And I'm using Eclipse IDE. I have already added the java-json.jar file to the build path of the project. but still I'm getting the below exception while running the code and no compilation error is displayed. I did clean the project and refreshed several times but still I end up with exception. is there anything missing?

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
Boz answered 24/3, 2015 at 6:15 Comment(2)
Add the jar also to the classpath in your laucher.Shellishellie
You also need to add the jar intro the project's lib folder: for WAR in WEB-INF/lib and for EAR in lib.Muoimuon
O
3

Download the Json jar from here and add it to the classpath. If its a web application then add its under lib's.

Officialdom answered 24/3, 2015 at 6:21 Comment(1)
Thank you but it's ok to use the existing java-json.jar fileBoz
B
2

I have added the same java-json.jar file to the Run configuration's class path of the particular java file. And now it's working absolutely fine. thanks everyone!!!

Boz answered 24/3, 2015 at 6:46 Comment(0)
W
2

Add maven dependency in pom.xml

<dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
    </dependency>
Woe answered 11/10, 2017 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.