Search code examples
javaeclipseclasspathnoclassdeffounderror

Java program works within IDE, but after compiling (eclipse) gives a java.lang.NoClassDefFoundError


Referenced Libraries Structure: (what I did manage to do, runs fine in IDE) enter image description here

StackTrace:

Exception in thread "main" java.lang.NoClassDefFoundError: org/newdawn/slick/SlickException
    at com.gametest.game.GameLauncher.main(GameLauncher.java:61)
Caused by: java.lang.ClassNotFoundException: org.newdawn.slick.SlickException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

Basically I am using slick and LWJGL to get the audio working, within the IDE it runs fine (build path configured, natives for lwjgl selected), but when compiled and ran, it crashes and in the console it gives above stacktrace.

I am running 64-bit macosx, code written and compiled in eclipse. Libraries used: lwjgl, slick (http://slick.ninjacave.com/)

ran from "Terminal" console using:

java -cp ~/Desktop/FirstGame.jar com.gametest.game.GameLauncher

This seems to be a common bug, but after a lot of time searching on the web, I have not come across an answer that solved it.

(edit) Relates to: ERROR!! AppGameContainer java.lang.ClassNotFoundException


Solution

  • I DID IT (I am so proud of myself, I figured it out myself, using a few documentations and some of my brain)

    sometimes, you need a little push from somebody to work yourself to the top.

    I basically fixed it by going into MANIFEST.MF and adding a line: Manifest file

    as well as moving all the jar files (and the binaries) in a single folder called "Game"

    When done correctly it looks something like this: The folder structure