问题描述
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app> 而且lib 也导入这些依赖包但项目运行的时候都会出现下面的异常,包括复制别人的项目 异常如下:java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:124)at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:897)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:873)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095)at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617)at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)at java.util.concurrent.FutureTask.run(FutureTask.java:138)at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)at java.lang.Thread.run(Thread.java:619)
解决方案
检查一下你的jsf-api.jar有没有在服务器的classpath里,你的截图是IDE里的classpath,作不得准。
解决方案二:
查一下你的发布包中有没有JSF-API包。强烈建议你用MAVEN 完成JSF工程的建立。-artifactGroupId=org.apache.myfaces.buildtools-arctifactArchetypeId=myfaces-archetype-helloworld具体的项目类型你可以GOOGLE一下
解决方案三:
从异常看是缺少包含javax.faces.webapp.FacesServlet这个类的包。