Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

java - Tomcat throws ClassNotFound exceptions for classes in other open eclipse projects

I have an eclipse project structure that looks something like this:

eclipse
    project a
    project b

All of these projects are Maven projects. Project B is an Eclipse WTP project and contains Project A as a dependency. I'm using the m2eclipse plugin.

When I deploy Project B to Tomcat (all from within Eclipse) it always throws errors saying that it can't find classes from Project A. The only way I can resolve this is to close Project A in Eclipse and do a mvn install command, so at this point Project A is treated like any other dependency.

I would like to not have to keep reopening and then closing Project A every time I make changes to it (which is pretty frequently at this stage).

I have tried adding Project A to Project B's Build Path, however that doesn't seem to do the trick. Again, it only works if I close the project in eclipse so it's treated like a normal maven dependency.

FYI I'm using the Helios version of Eclipse. Project B is a Spring project, so naturally Tomcat falls over when it imports all the beans etc.

Does anyone have any suggestions? Thanks a lot.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

What you need to do is this:

  1. In Eclipse go to Window > Show View > Servers > and open tab called Servers
  2. In Servers, double click the server you want
  3. This action should open a window entitled Overview, with your selected Server in the TAB
  4. In this window select: Open launch configuration, and click the link.
  5. In the Edit Configuration window, select the tab called Classpath
  6. In the ClassPath textbox, select the line: User Entries
  7. Now push the button on the right entitled: Add Projects
  8. In the resulting Project Selection window select the external project you want the server to find via click.
  9. Close these windows by clicking Apply then OK as appropriate as you work up the stack
  10. Restart your server in the Overview window

You should be ready to go. It's actually only a 2 minute exercise. Good luck


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...