Azarus Azarus - 1 year ago 144
Java Question

Java Socket.IO missing dependency NoClassDefFoundError

Hi guys im pretty new to java. Coming from .NET, C++. I am trying to get my head over with an error that is killing me since days and i am unable to fix it.

I get this error when i try to run my .jar file

java.lang.NoClassDefFoundError: com/github/nkzawa/emitter/Emitter$Listener

I have no clue what else it needs, or why its not loading the

Any help appreciated.


Crashing code part:

socket = IO.socket("");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener()

// ...




Is there any other way to make sure that these dependencies are shipped with the final jar file so i don't have dependency issues on the end-user's machine?

Answer Source

When you compile C++ code, you have to give the compiler a list of (shared) libraries which your code depends on. In Java, you can specify a list of JARs which are added to the "classpath". Unlike C++, Java allows to change the classpath after the code has been compiled. So you can add additional elements or remove existing ones. In C++, you usually can replace the DLL file on disk but you need special tricks to get your code to load more DLLs or forget about ones that it was linked against.

This causes all kind of weird problems like the one which you experience right now: Eclipse builds the classpath for you, everything looks fine. You export the project as an executable JAR and suddenly, you have to do a lot of tedious work just to replicate a click of a button in the IDE.

The most simple way to get the classpath is to start your program in the IDE once, switch to the Debug perspective and check the properties of the process which Eclipse created. It will display the Java command line which it built. It's not a pretty sight.

Copy the whole thing into a .cmd file and use that to start your application.

You can also use Maven to create executable JARs with several options how to handle dependencies: How can I create an executable jar with dependencies using Maven?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download