0

I've been attempting to export my new Java code from Eclipse into a JAR and have been having issues with the JSON Libraries. At first, I exported using my current JDK, which would compile for Java 15. However, when I attempted to run it, it would not work because my JRE is Java 1.8. Then I changed the environment in Eclipse to 1.7, as apparently my code had some incompatibilities with 1.8, and since then, I'm able to export to a JAR file that runs and starts my GUI, but each time it crashed because it cannot find the JSON classes as the following stacktrace shows:

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException
        at aoClient.AoApi.<init>(AoApi.java:10)
        at aoClient.Main.main(Main.java:224)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
        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 tried to use a different version of JSON in the Maven POM file, without success, and I have tried linking the JAR file of the JSON library to my build path, and even checking the order and export tab of the build path with no change. I've attempted to use different versions of JSON in Maven, and to remove JSON from Maven to only have the libraries added by Java. I've also tried running Maven install rather than Eclipse export to JAR, but I'm still getting the same error. And finally, and probably the most infuriating part is that when I run the program from Eclipse, it works perfectly.

I also tried to disable Maven from the project and manually adding the two libraries I'm using through the build path, and I get the exact same result. And it may be useful to know that I noticed that no images are loading even though they are called before aoClient.AoApi

I'm running windows 10 and eclipse 2020-12 with java 1.8.0_281 as my JRE.

Can anyone explain to me why this doesn't work and how I can fix it?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

Thank you @J Fabian Meier for your comment

Have you read stackoverflow.com/q/574594/927493 ? – J Fabian Meier

I was able to run the compilation successfully with that article after several tries by adding the plugins inside the plugins tag. It didn't include the images but at least it's running.