NoClassDefFoundError when trying to parse JSON with JSON simple
You're not including the Simple JSON jar file in your classpath when running. You want:
// Unixjava -cp .:json-simple-1.1.1.jar MyProgram// Windowsjava -cp .;json-simple-1.1.1.jar MyProgram
(The :
or ;
is the path separator for the relevant operating system.)
When you compile Java and specify a classpath, that's just telling the compiler about the classes to compile against - it doesn't include the library in the result of the compilation, so you still need to specify the classpath in order to run the code, too.
Did you compile your code with -cp json-simple-1.1.1.jar?
Sometime ago, I made a Test.java, and compiled with:
javac -cp json-simple-1.1.1.jar Test.java
Then:
java -cp .:json-simple-1.1.1.jar Test
And It ran perfectly.
If you are using an IDE, download the jar from this link.In netbeans and eclipse you can add this jar by right clicking on project then selecting properties->libraries->Add jar->Select the jar and click ok.