现象:
Web项目使用Maven管理jar包依赖,web.xml文件中有如下配置:
[html] view plain copy <!-- 配置Spring里的log4j监听器 --> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> 在Tomcat里运行项目时报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener.原因:
在部署过程中没有将依赖的jar包自动拷贝到/WEB-INF/lib目录下。
解决办法:
选中项目右键,Properties -> Deployment Assembly -> Add... -> Java Build Path Entries -> Maven Dependencies。
这个设置保存在项目的.classpath文件中,也可以直接修改此文件。配置好以后会多出如下一段xml:
[html] view plain copy <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> </attributes> </classpathentry> 注意是在部署的时候才会拷贝jar包到lib目录下,而不是在更新Maven依赖的时候。参考资料:Maven把依赖包拷贝到lib下
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ego_ecust/article/details/4712206