开发者

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 de开发者_Go百科pendency 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?


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.


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.


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


  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜