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

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

问题描述

我已经遇到这个问题了几次,只是偶然发现(半)可靠的解决方案,所以以为我会把它发布在这里,以防万一它帮助别人,或者如果我忘记了,还要询问是否有任何人知道什么是潜在的原因,以及为什么我的修复工作可行。



问题 - 我有一个spring 3 webapp,我想使用运行在服务器在Eclipse中运行Tomcat 7服务器上的选项。有些项目这只是工作,但有些似乎处于一个破碎的状态,每次服务器启动我得到一个类没有找到:org.springframework.web.servlet.DispatcherServlet。



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



我以前尝试过很多东西最后注意到该项目在问题面板中发出警告:

 类路径条目org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER 
将不会导出或发布。可能会导致运行时ClassNotFoundException。

也许我应该早点注意到这个。



无论如何,选择此项并执行快速修复修复问题,我可以很高兴地运行我的项目。快速修复是:将相关的原始类路径条目标记为发布/导出依赖关系。



麻烦的是,尽管这样做,我不知道它是什么手段。完成后,我的项目配置看不到任何明显的变化。我很想知道实际的问题是什么,如果我能避免再次发生。我也想知道是否有一些我可以做的事情(除了执行快速修复),这将修复它,因为我觉得我几乎尝试了其他一切。



感谢您的帮助。

解决方案

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



您发现的快速修复对您而言也是一样的。如果您对封面下发生的事情感到好奇,请在快速修复之前和之后查看.classpath文件。快速修复将类路径条目标记为一些装配信息。


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.

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.

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.

Thanks for your help.

解决方案

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.

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.

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

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