1

In my project named Bookyard.Server, I reference another project of mine named Bookyard.Contracts.

In Eclipse for Java EE, Mars 2, I set the Build Path and Project References for the Bookyard.Server project like so:

enter image description here

enter image description here

I also added the bin folder of the Bookyard.Contracts project to the %CLASSPATH% like so:

enter image description here

However, when I debug my Bookyard.Server project, at the line where it references the contracts project, it raises a java.lang.NoClassDefFoundError exception for practice/bookyard/contracts/Constants.

Bookyard.Server

import practice.bookyard.contracts.Constants;
...
if (!body.get("sub").toString()
       .contentEquals(Constants.JWT_SUBJECT_LOGIN_REQUEST))
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
  • 1
    try to add your dependent project in Deployment Assembly also – Jekin Kalariya Aug 31 '16 at 06:21
  • @JekinKalariya Thank you. I am a complete beginner as far as Java is concerned. I have no idea how to do that. Could you please point me to a page that explains how to do that? – Water Cooler v2 Aug 31 '16 at 06:22
  • Its simple as you can seee deployment assembly tag in your eclipse property snap shot , just add project there same as you add in build path – Jekin Kalariya Aug 31 '16 at 06:25
  • further reference regarding deployment assembly is here https://www.genuitec.com/products/myeclipse/learning-center/basics/myeclipse-deployment-assembly/ – Jekin Kalariya Aug 31 '16 at 06:26
  • @JekinKalariya Thank you. That was easy. But it tells me now that there are errors in my contract project. Which isn't a problem. I'll figure out what they are. Only. I am new to the eco-system and tools, so could you please tell me how I may check build errors. When I build my project, the **Console** window doesn't report build progress. Where can I see that? I guess that's a new question but it'll help if you could tell me. – Water Cooler v2 Aug 31 '16 at 06:37
  • generally build error will display in your servers output log if you are using tomcat it would be in Catalina.log, but prior to that it would be better if you check is there any compilation error in your project by showing problems view in eclipse window – Jekin Kalariya Aug 31 '16 at 06:40
  • Sure, there's so much I don't understand. I think I'll post a separate question. BTW, the contracts project isn't a servlet one. It's just a simple project with an interface and a class and a bean. Which window would show me the build progress for that project? And if you'd like to put your commend about the Deployment Assembly down as an answer, I could mark that as the correct one. It'll help someone like me in the future. – Water Cooler v2 Aug 31 '16 at 06:49
  • @JekinKalariya I just asked a new question about that here: http://stackoverflow.com/q/39242724/303685 – Water Cooler v2 Aug 31 '16 at 06:57
  • Add the project in deployment Assembly – Danyal Sandeelo Aug 31 '16 at 06:58
  • @ran http://stackoverflow.com/q/39072303/303685 – Water Cooler v2 Aug 31 '16 at 07:44

3 Answers3

5

As there is dependency among the projects you need to add your Bookyard.Contracts. under Deployment Assembly section of project properties

Jekin Kalariya
  • 3,475
  • 2
  • 20
  • 32
1

I got the NoClassDefFoundError after some reorganizing of my Eclipse 2020-12 workspace in which I have 8 cooperating projects. The projects build upon (i.e. depend on) one another, and I had entered the dependencies using Package Explorer -> right click on project name -> Build Path -> Configure Build Path ... -> "Projects" Tab -> "Add..." Button.

Background: Because I ran into so many problems with the Java Module System, I decided to avoid it altogether and continue to use Java 1.8 even though I have (don't ask me why) JavaSE-13 (also shown as "JRE 13") as my runtime. Now back to my observations and finally the solution:

Observation 1: Some of my projects were ticked "Enable project specific settings" and others were not.

Observation 2: In the "Java Build Path" dialog -> Tab "Projects" I noticed that the information about the "Required projects on the build path" was not consistent. The same lower-level project was shown as "Is modular" on some projects that used it, and as "Is not modular" on other projects. (To see this "modular or not" info about a required project, expand its line by clicking on the > in front of the name).

Solution (part 1): For all my projects in the workspace I made sure they did NOT have a tick in "Enable project specific setting" in the dialog "Java Compiler" of the project properties. So that all of them should now share the Workspace Settings for "Java Compiler".

Solution (part 2): In the list of the "required projects" of each project I removed the entries for the projects that were listed as "Is modular" and immediately added them again. After this operation, all required projects of all my 8 projects were listed as "Is not modular".

Effect: Now the software runs fine again.

Hypothesis 1: Maybe the class loaders use different search mechanisms when they look for class files in projects, depending on whether the USING project declares the projects it uses as modular or not.

Hypothesis 2: Maybe Eclipse COPIES the "is modular" information of a lower-level project when it adds it to the "required projects" of another project. With the effect that if the "is modular" information changes, the depending projects are out of sync. If this is true, Eclipse should just REFER to the "is modular" information receive an event in case it changes.

My opinion: I regard this is an error. Why? A project which requires another one should not depend on whether the other project is "modular" or not.

1

Sometimes you get NoClassDefFoundError if your class has an uncaught Exception in constructor or static block of your class. The main error is suppressed by NoClassDefFoundError.

krishna T
  • 425
  • 4
  • 14