The problem is your runtime classpath. There's no magic with this error. It quite simply means that org.json.JSONException is not on your runtime classpath. Find the jar that has this class in it and put it on your runtime classpath.

Note that the jars / classes needed for runtime are not necessarily the same as those needed for compiling. You quite often need more on your runtime classpath than your compile classpath. If JSONException isn't used explicitly in the code you are compiling, then it won't have to be on your compile classpath. However, if one of the dependencies to your code needs JSONException and it's not on your runtime classpath, you will get a NoClassDefFoundError.

One other issue that can possibly occur is that you have 2 different versions of the json jar on your classpath. Usually the first version of the class on the classpath gets loaded and the other ignored. If the first jar didn't have the version / signature of JSONException you needed in it but the second did, the correct class you would still get ignored, since it was further down on the classpath.

Answer from TheEllis on Stack Overflow
🌐
Maven Repository
mvnrepository.com › artifact › org.json › json
Maven Repository: org.json » json
December 24, 2025 - JSON is a light-weight, language independent, data interchange format. See http://www.JSON.org/ The files in this package implement JSON encoders/decoders in Java. It also includes the capability to convert between JSON and XML, HTTP headers, Cookies, and CDL.
🌐
Android Developers
developer.android.com › api reference › jsonexception
JSONException | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
Top answer
1 of 4
2

The problem is your runtime classpath. There's no magic with this error. It quite simply means that org.json.JSONException is not on your runtime classpath. Find the jar that has this class in it and put it on your runtime classpath.

Note that the jars / classes needed for runtime are not necessarily the same as those needed for compiling. You quite often need more on your runtime classpath than your compile classpath. If JSONException isn't used explicitly in the code you are compiling, then it won't have to be on your compile classpath. However, if one of the dependencies to your code needs JSONException and it's not on your runtime classpath, you will get a NoClassDefFoundError.

One other issue that can possibly occur is that you have 2 different versions of the json jar on your classpath. Usually the first version of the class on the classpath gets loaded and the other ignored. If the first jar didn't have the version / signature of JSONException you needed in it but the second did, the correct class you would still get ignored, since it was further down on the classpath.

2 of 4
1

The issue would appear to be that you are not adding the dependent jars to your resultant jar.

I have created a similar test jar, with the following structure (checking using jar tf)...

META-INF/
META-INF/MANIFEST.MF
BeanIt.class
TestBean.class
lib/
lib/opencsv-3.7.jar
lib/commons-lang3-3.4.jar

My manifest...

Main-Class: BeanIt
Class-Path: lib/opencsv-3.7.jar lib/commons-lang3-3.4.jar

In order to create this jar, you need to perform a command something similar to this...

jar cfm App.jar MANIFEST.MF BeanIt.class TestBean.class lib

You can see that I've added my lib folder to the jar and referred to its contents on the classpath in the manifest.

So, you can update your existing lib, like this...

jar uf App.jar path

Where path is the root path of your path/to/lib directory. And it will simply add that to your jar.

You can check your jar first using jar tf, to see what it contains.

If you are still having difficulties getting it to work, then you can look at a "FAT JAR" solution whereby you expand all the internal jars classes and flatten them all out to a single JAR containing all the necessary classes. They use decision mechanisms to deal with class conflicts in different JARs. Tools such as sbt-assembly or OneJar may be what you need here, if you are unable to get your JAR working the way you expect.

🌐
Experts Exchange
experts-exchange.com › questions › 27239325 › org-json-JSONException-not-found.html
Solved: org/json/JSONException not found | Experts Exchange
May 26, 2011 - I'm using json-lib-2,4-jdk15.jar from: http://sourceforge.net/projects/json-lib/files/json-lib/json-lib-2.4/json-lib-2.4-jdk15.jar/download and had no problems. I didn't reference JSONException explicitly though in my code - but do you really need to do it? Just catch(Exception ) if you need.
🌐
Jar-Download
jar-download.com › home › com.jwebmp › json › 0.63.0.54 › source code › jsonexception.java
org.json.JSONException Maven / Gradle / Ivy
org.json.JSONException maven / gradle build tool code. The class is part of the package ➦ Group: com.jwebmp ➦ Artifact: json ➦ Version: 0.63.0.54
🌐
Stleary
stleary.github.io › JSON-java › org › json › JSONException.html
JSONException
The JSONException is thrown by the JSON.org classes when things are amiss.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › org_json › org_json_quick_guide.htm
Org.Json - Quick Guide
Following example shows how to handle JSONException. package com.tutorialspoint; import org.json.JSONException; import org.json.XML; public class JsonDemo { public static void main(String[] args) { try { //XML tag name should not have space.
🌐
Findjar
findjar.com › index.x
org.json.JSONException - JAR Search - findJAR.com
This page shows all JAR files or Java classes containing the string org.json.JSONException.
🌐
Stack Overflow
stackoverflow.com › questions › 14039847 › org-json-jsonexception-in-java-application
org.JSON.JSONException in Java Application - Stack Overflow
Are you sure you don't need any of these : jarfinder.com/index.php/java/info/org.json.JSONException ? TJ- – TJ- 2012-12-26 11:20:50 +00:00 Commented Dec 26, 2012 at 11:20 · Yes, I'm not using any other conflicting jar · Vardan Gupta – Vardan Gupta · 2012-12-26 11:29:29 +00:00 Commented Dec 26, 2012 at 11:29 ·
🌐
Coderanch
coderanch.com › t › 775279 › java › org-json-JSONException-parse-complex
org.json.JSONException when trying to parse complex JSON subsection (Java in General forum at Coderanch)
Am facing impediments when using Java 1.8 and the org.json lib to marshal & parse a complex JSON object... JSON dependency: JSON response payload: This productsJsonObject contains the entire JSON above am having trouble getting the subsection which starts with the  "productTypes" JSON key.
🌐
TutorialsPoint
tutorialspoint.com › org_json › org_json_exception_handling.htm
Org.Json - JSONException Handling
String xmlText = "<Other ... Details>null</Other Details> Misshaped close tag at 34 [character 35 line 1] JSONException is a Runtime Exception and is not required to be declared as throws statement....
🌐
Coderanch
coderanch.com › t › 666886 › java › package-org-json-exist
package org.json does not exist [Solved] (Beginning Java forum at Coderanch)
I got no words. Both answers helped me. I specified the .JAR and IT WORKED: $ javac -cp /usr/share/java/json-20160212.jar JsonParser.java Thank you, guys! Thank you, Code Ranch! ------------------------------------------------------ A brief (parentheses) here, just for reflection.
🌐
GitHub
github.com › spring-attic › spring-cloud-deployer-kubernetes › issues › 142
Remove extra occurrences of org.json.JSONObject on the class path · Issue #142 · spring-attic/spring-cloud-deployer-kubernetes
July 14, 2017 - Found multiple occurrences of org.json.JSONObject on the class path: jar:file:/Users/trisberg/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class jar:file:/Users/trisberg/.m2/repository/org/json/json/20140107/json-20140107.jar!/org/json/JSONObject.class You may wish to exclude one of them to ensure predictable runtime behaviour
Author   trisberg
🌐
Java2s
java2s.com › Code › Jar › j › Downloadjavajsonjar.htm
java json - Jar File Download
April 26, 2021 - java2s.com | Email: | © Demo Source and Support. All rights reserved
🌐
Bukkit
bukkit.org › threads › problem-loading-libraries-with-maven-java-lang-noclassdeffounderror-org-json-jsonobject.428354
Solved - Problem loading libraries with Maven... "java.lang.NoClassDefFoundError: org/json/JSONObject" | Bukkit Forums
August 9, 2016 - Hey everybody. So I'm having a bit of trouble just using an external library, in this case, org.json (though it's the same problem for any maven...