Search code examples
javaeclipsereferenceproject

NoClassDefFound in Java / Eclipse: How do I make a clean and easy reference to another project?


I have been searching for this problem all over. However, I cannot find any good explanation or how to actually solve this issue.

The problem is that then I add a Project Reference in my project, it will not give me any compile-time errors. However, when I use the referenced project in my main project, I get the java.lang.NoClassDefFoundError.

To me, this is insane. If I add a Project Reference, I expect that project to be available during runtime. It is not, apparently.

I add it by RIGHT-CLICK on the Project --> Properties --> Projects --> and then add my project that is in the workspace.

And no, I don't really want to export my referenced project to a JAR and import that file, since that means I have to import it every time I change the referenced project.

It should be so easy - like in Visual Studio - to add the project and then be done with it. What am I missing?


Solution

  • It seems I found the problem.

    The "MiscLibrary", the project I am referencing from my MainProject, has another external JAR referenced. If that wasnt also imported in the MainProject, I get those weird errors.

    Its very bad that 1) I can compile it without any errors or warning! 2) In runtime, the error messages give no indication what so ever that I am missing a reference to another library. Instead, it says it cannot find MiscLibrary, when in fact the problem is the missing external lib in MiscLibrary...