I'm very new to Java world. I want to add the Json lib to compile my program. I downloaded the file from here.
When I tried to compile the program with
javac -classpath json.jar MyClassName.java
I'm getting the error :
Note: JsonSimpleExample.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
And when I tried to run :
java MyClassName
I'm getting:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONObject
at MyClassName.main(MyClassName.java:9)
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more
Where I'm making the mistake?
You have to use the -classpath when running with java as well.
java -classpath json.jar MyClassName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With