Issue
I am currently experiencing issues whilst using external libraries in Eclipse. Whenever I am trying to launch my program it throws a NoClassDefFound exception. I am obviously doing something wrong. Could someone re-explain for me how to properly include them into your project? (Yes I have already done a lot of research on this and got recommended to use Maven dependencies which I don‘t want. Also I have found some threads that were more relevant to my issue but nothing helped. So yeah, I would really appreciate it if someone could explain what exactly to do.)
I am using the newest ver of eclipse together with java 8 (usually 13 but that did not fix my error). It only throws the exception on runtime so, it compiles without any errors.
Project setup: http://prntscr.com/udsxts
Manifest file:
Manifest-Version: 1.0
Main-Class: me.sxlver.consoleclient.Main
Class-Path: lib/java-json.jar lib/snakeyaml-1.26.jar
Exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
at me.sxlver.consoleclient.Main.main(Main.java:20)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
(I am just creating an instance of JSONObject)
Java Build Path: http://prntscr.com/udtgjn
Libraries: http://prntscr.com/udtqas
Solution
From the Run menu, select Run Configurations...
Select Dependencies tab, then click on button Add External JARs
A file chooser window will appear. Navigate to the location of the relevant JAR and select it.
Answered By - Abra
Answer Checked By - Marie Seifert (JavaFixing Admin)