最近新建了一个JSF项目(网上查到用Struts,Spring MVC也会如此),配置好以后用Eclipse启动Tomcat报了如下错误:严重: Error loading WebappClassLoader
- context: /jsf2nd
- delegate: false
- repositories:
- /WEB-INF/classes/
- ----------> Parent Classloader:
- org.apache.catalina.loader.StandardClassLoader@1172e08
- javax.faces.webapp.FacesServlet
- java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
- at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1128)
- at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
- at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
- at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
- at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
- at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
- at org.apache.catalina.core.StandardService.start(StandardService.java:525)
- at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
- at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
- at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
- 2011-12-8 9:11:27 org.apache.catalina.core.StandardContext loadOnStartup
- 严重: Servlet /jsf2nd threw load() exception
- java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
- at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1128)
- at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
- at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
- at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
- at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
- at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
- at org.apache.catalina.core.StandardService.start(StandardService.java:525)
- at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
- at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
- at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
网上搜了几种解决方案:1、关掉myeclipse,把原来的tomcat换掉,如果是安装版的就卸载,重新放一个tomcat,启动myeclipse,配置tomcat,部署,再启动tomcat,一切OK。2、之前jar包我是通过Build path -> Configure build path-> Add External JARs的方式添加的,程序编译,Tomcat启动都很正常,没有错误。可是一访问jsp页面就报上述错误。 苦思不得其解,但看了错误信息说是找不到org.springframework.web.servlet.DispatcherServlet类,所以我就干脆将spring.jar,spring-webmvc.jar等jar包通通手工添加到/WEB-INF/lib目录下,并且将default output folder值改为projectName/WebContent/WEB-INF/classes 问题就得以解决了。
这两种解决方案试了都不行,但是大体了解到可能是jar包没有导入进去,所以进了eclipse的工程目录,找到对应的存放jar包的目录:.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\jsf2nd\WEB-INF\lib,发现果然少了两个jar包,将之放入后问题就解决了。
错误原因:至今未能查明究竟是哪个地方出错了才使得eclipse不能将jar包放到eclipse的tomcat插件下面。
可能的几个原因:1、我的eclipse选择的默认编译是jdk1.5,而这个项目用的是Tomcat6, 2、我的Eclipse里面默认设置的tomcat的编译器也是1.5