I downloaded the following link:
http://www.java2s.com/Code/JarDownload/java/java-json.jar.zip
I then added the jar to the build path: Right click the Project > Build Path > Configure build path > Select Libraries tab > Click Add External Libraries > Select the Jar file Download.
I was able to use the java-json library without eclipse giving any errors. However, when I went to export the project to a jar, there was no option to include the java-json Referenced Libraries as part of the jar. So I assumed that by adding the libraries to the Build Path, I did not have to export the external jars (there was no option to do that anyway):
After I created the jar, I ran the program:
java -jar gateway.jar -p 1732
And I got the following error:
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/json/JSONException
at com.guarddoggps.main.UdpServer.run(UdpServer.java:28)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
It seems that the runtime cannot find the class JSONException even though it is clearly in the java-json.jar file I included in the build path and is present in "Referenced Libraries" in Eclipse.
What might I be missing here?