Tomcat 对其他打开的 eclipse 项目中的类抛出 ClassNotFound 异常
我有一个 Eclipse 项目结构,看起来像这样:
eclipse
project a
project b
所有这些项目都是 Maven 项目。项目 B 是一个 Eclipse WTP 项目,包含项目 A 作为依赖项。我正在使用 m2eclipse 插件。
当我将项目 B 部署到 Tomcat 时(全部来自 Eclipse 内),它总是抛出错误,指出无法从项目 A 中找到类。解决此问题的唯一方法是在 Eclipse 中关闭项目 A并执行 mvn install 命令,因此此时项目 A 被视为与任何其他依赖项一样。
我不想每次对项目 A 进行更改时都必须重新打开然后关闭项目 A(在这个阶段这种情况很常见)。
我尝试将项目 A 添加到项目 B 的构建路径中,但这似乎并没有解决问题。同样,只有当我在 Eclipse 中关闭项目时它才有效,因此它被视为正常的 Maven 依赖项。
仅供参考,我正在使用 Helios 版本的 Eclipse。项目B是一个Spring项目,所以Tomcat在导入所有bean等时自然会崩溃。
有人有什么建议吗?多谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您需要做的是:
您应该已准备就绪。实际上只需2分钟的练习。祝你好运
What you need to do is this:
You should be ready to go. It's actually only a 2 minute exercise. Good luck
如果您转到项目属性,选择“部署程序集”项,单击“添加...”并选择“项目”,则可以添加依赖项目,问题应该得到解决。
If you go to the project properties, pick the item "Deployment Assembly", click "Add..." and choose "Project", you can add the dependent project and the issue should be solved.
tomcat找不到你的类的原因是tomcat看不到eclipse中的项目依赖。要解决此问题,您可以将项目 a 的 bin 文件夹添加到从项目 b 运行的应用程序的 tomcat 类路径中。
The reason that tomcat cannot find your classes is that the project dependency in eclipse is not seen by tomcat. To resolve the issue you can add the bin folder of project a to the tomcat classpath of the app running from project b.
右键单击添加到容器服务器的Web项目,选择Maven,然后选择禁用工作区解析。然后,您的依赖项项目将开始像任何其他依赖项一样显示为 jar。
Right click on the web project which is added to container server and select Maven and then select Disable Workspace Resolution. Then your dependency project will start appearing as a jar like any other dependencies.
您安装了了解 WTP 的 m2eclipse 扩展吗?如果没有它,m2e 将无法在 WTP 项目中正常工作。请参阅:
https://docs.sonatype.org/display/M2ECLIPSE/WTP+迷你+操作方法
Have you installed the m2eclipse extension that know about WTP? Without it m2e will not work correctly for WTP projects. See this:
https://docs.sonatype.org/display/M2ECLIPSE/WTP+mini+howto
简单的方法:
运行 ->运行配置...->类路径
Simple way :
Run -> Run Configurations... -> Classpath