Please add the following dependency http://mvnrepository.com/artifact/org.json/json/20080701
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20080701</version>
</dependency>
Answer from Raghu K Nair on Stack OverflowPlease add the following dependency http://mvnrepository.com/artifact/org.json/json/20080701
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20080701</version>
</dependency>
No.. It is not proper way. Refer the steps,
For 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.
For 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.
This is the proper way! Don't forget to remove environment variable. It is not required now.
Try this. Surely it will work. Try to use Maven, it will simplify you task.
Caused by: java.lang.NoClassDefFoundError: org.json.JSONObject error
java - org.json dependency with Maven gives NoClassDefFoundError - Stack Overflow
java - org.json.simple.jsonObject throws noclassdeffounderror proguard maven - Stack Overflow
NoClassDefFoundError: org/json/JSONObject
Hi all,
I am working with a JSON object and when I launch my project I get the following error:
java.lang.NoClassDefFoundError: org/json/JSONObject
viewmodels.LaunchViewModel.buildNextLaunch(LaunchViewModel.java:64)Looking at line 64...
JSONObject jsonObj = new JSONObject(getHTML("..."));Looks like I have not setup the dependencies correctly. I am working with IntelliJ with Gradle and I have imported JSON into my external libraries as seen here...
https://i.imgur.com/8VqLFf9.jpg
and here...
https://i.imgur.com/MFupkXg.jpg
My question is does it need to be added to the build.gradle file? Here are my dependencies:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
}I think that may be the culprit? But I am still pretty new to this process so any pointers would be sweet.
Thanks!
Edit for mods: The two screenshots are of my external libraries, no code in those. I replaced the remaining screen shot with a code block. Thanks!
Add json jar to your classpath
or use java -classpath json.jar ClassName
Or add this to your maven pom.xml depedencies:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
As of today (15th July 2020), you need to use latest maven repository as per below:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20200518</version>
</dependency>
For any new version in the future, you can check it here:
- https://mvnrepository.com/artifact/org.json/json
Then simply replace 20200518 with latest new version value.
Download the Json jar from here and add it to the classpath. If its a web application then add its under lib's.
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!!!
It is better to add a line to copy the JSON jar to your application's WEB-INF/lib instead of Tomcat lib as your application uses it, not tomcat itself
You need to provide json libraries in classpath when you run the application as well. Easiest way would be put them in your tomcat's lib folder put json-20160810.jar in lib of tomcat