mh377
mh377

Reputation: 1856

java multiple projects ClassNotFoundException

I have 2 java projects ProjectA (java web app) and ProjectB (contains other java classes) in my eclipse IDE. e.g.

ProjectA                             ProjectB
|_HelloWorld.java                     |_PrintHelloWorld.java
   |_HelloWorld(                         |_print()
     new PrintHelloWorld().print()
      )

So ProjectA has a class with a method that is calling a method from a class in ProjectB. In Order to get these projects to build, I have built ProjectB and added the jar as a dependency on ProjectA's build-path. So I don't get any compilation errors and the project seems to build fine.

However, when I debug through the code. I get ClassNotFoundException at the line where ProjectA calls the method in project B

Does anybody know what I am doing wrong/have missed out?

Upvotes: 0

Views: 2515

Answers (4)

CharithaMadu
CharithaMadu

Reputation: 61

Using the following steps add the project to Deployment Assembly.

right click on project > Properties > Deployment Assembly > Add > Project > Select the project to be added as the dependency and then click Apply and Ok.

This worked for me after trying several options.

Upvotes: 3

coopr
coopr

Reputation: 36

Create a war file if the needed classes are in that.

The compiler build path is not the same as the deploy path. You may need to explicitly add the dependent jar in the Deployment Assembly option

Upvotes: 0

Harry Joy
Harry Joy

Reputation: 59690

  1. Right click on ProjectA.
  2. Go to Build Path-->configure build path
  3. Select Project tab.
  4. Add ProjectB in it by clicking on Add button.
  5. Press OK.

Note:- This will be helpful when you are running your application in eclipse. When building it make sure to build ProjectB and add it to ProjectA at proper place.

Hope this helps.

Upvotes: 0

dogbane
dogbane

Reputation: 274778

Instead of adding ProjectB's jar to ProjectA, add the whole project as a dependency as follows:

  • Open ProjectA Properties > Java Build Path
  • Select the Projects tab
  • Add ProjectB

Link to Eclipse User Guide.

Upvotes: 1

Related Questions