启动 Tomcat 时出现 ClassNotFoundException DispatcherServlet(Maven 依赖项未复制到 wtpwebapps) [英] ClassNotFoundException DispatcherServlet when launching Tomcat (Maven dependencies not copied to wtpwebapps)

查看:27
本文介绍了启动 Tomcat 时出现 ClassNotFoundException DispatcherServlet(Maven 依赖项未复制到 wtpwebapps)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到过几次这个问题,只是偶然发现了一个(半)可靠的解决方案,所以我想我会把它贴在这里,以防它对其他人有帮助,或者万一我忘记了,也为了询问是否有人知道根本原因是什么以及为什么我的修复有效.

I've run into this problem a few times and only just stumbled upon a (semi-) reliable solution, so thought I would post it here in case it helps anyone else, or in case I forget it, and also to ask if anyone has any idea what the underlying cause is and why my fix works.

问题 - 我有一个 spring 3 webapp,我想使用 Eclipse 中的 Run on Server 选项在 Tomcat 7 服务器上运行.对于某些项目,这确实有效,但有些项目似乎处于损坏状态,每次服务器启动时,我都找不到一个类:org.springframework.web.servlet.DispatcherServlet.

The problem - I have a spring 3 webapp that I want to use the Run on Server option in Eclipse to run on a Tomcat 7 server. With some projects this just works, but some seem to get in a broken state whereby every time the server starts up I get a class not found: org.springframework.web.servlet.DispatcherServlet.

经过一番调查,我发现项目的 maven 依赖项没有被复制到 ${PROJECT_LOCATION}/.metadata/.plugins/org.eclipse 中的 WEB-INF/lib.wst.server.core/tmp0/wtpwebapps/

After some investigation I found out that the project's maven dependencies had not been copied to WEB-INF/lib in ${PROJECT_LOCATION}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/

我尝试了很多东西,最后才注意到该项目在问题面板中有警告:

I tried a lot of things before finally noticing that the project had a warning in the Problems panel:

Classpath entry org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER 
will not be exported or published. Runtime ClassNotFoundExceptions may result.

也许我应该早点注意到这一点.

Perhaps I should have noticed this sooner.

无论如何,选择它并执行快速修复"可以解决问题,我可以愉快地运行我的项目.快速修复是:将关联的原始类路径条目标记为发布/导出依赖项".

Anyway, selecting this and performing the "Quick Fix" fixes the issue and I can happily run my project. The quick fix is to: "Mark the associated raw classpath entry as a publish/export dependency".

问题是,虽然这有效,但我不知道这意味着什么.完成后,我看不到我的项目配置有任何明显的变化.我很想知道实际问题是什么,以及我是否可以避免它再次发生.我还想知道是否有我自己可以做的事情(除了执行快速修复)可以修复它,因为我觉得我几乎尝试了其他所有方法.

Trouble is, although this works, I don't know what it means. I can't see any obvious changes in my project configuration after it's done. I would quite like to know what the actual problem is and if I can avoid it happening again. I would also like to know if there is something I could have done myself (other than performing the quick fix) that would have fixed it, because I feel like I tried pretty much everything else.

感谢您的帮助.

推荐答案

查看项目属性下的部署程序集"部分.此页面的内容指定如何将您的项目组装到正在运行的应用程序中.特别是,您可以在此处控制您的项目引用的哪些库应该与它一起打包.选择添加 -> Java 构建路径条目.您将能够从现有的构建路径条目中进行选择以包含在程序集中.

Take a look at "Deployment Assembly" section under project properties. The content of this page specify how your project is to be assembled into a running application. In particular, this is the place where you can control which of the libraries that your project references, should be packaged with it. Select Add -> Java Build Path Entries. You will be able to pick among your existing build path entries to include in the assembly.

您找到的快速修复对您做了同样的事情.如果您对幕后发生的事情感到好奇,请在快速修复之前和之后查看您的 .classpath 文件.快速修复用一些程序集信息标记类路径条目.

The quick fix that you found did the same thing for you. If you are curious about what happens under the covers, take a look at your .classpath file before and after the quick fix. The quick fix tags the classpath entry with some assembly information.

这篇关于启动 Tomcat 时出现 ClassNotFoundException DispatcherServlet(Maven 依赖项未复制到 wtpwebapps)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆