I'm currently developing a project that needs a json creator class in java. I am trying to use the json-simple library, and have already downloaded and copied the .jar file to my projects directory. I am compiling my java file using
javac -cp json-simple.jar report.java
however when i try to run it i get this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONObject
at report.main(report.java:22)
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONObject
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
I am using ubuntu and cannot use an IDE like eclipse, can anyone help me? thank you in advance.
ok guys I have discovered the solution! For anyone that eventually meets the same problem the solution is simple, after compiling the program dont run it like the other java files, you need to give the command -cp
to say the directory of the .jar file, in this example it looks something like this:
java -cp json-simple.jar: report.java