Reputation: 2201
This is my java code
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class PlutoMake {
public static void main(String[] args) throws JSONException {
}
}
and I compile it with this and it compiles without error
javac PlutoMake.java -cp java-json.jar
Now I copied this project from eclipse from windows, and using that jar it worked fine. I could access all the json functions. But here on linux, when I run it, I get
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
If I remove the throws JSONException
then I can run it. So for some reason I can import the jar but I can't access any of its functions/exceptions without crashing my program...
Jar file is from the answer from this link Importing JSON into an Eclipse project
Does anyone know how to fix this?
Thanks
Upvotes: 0
Views: 608
Reputation: 51
When you have create project in eclipse on linux you need configure buildpath inserting the jar
Upvotes: 0
Reputation: 159794
Add the jar file to the runtime classpath
java -cp java-json.jar:. PlutoMake
Upvotes: 1