加载WebappClassLoader时出错

时间:2013-09-23 09:37:51

标签: java tomcat

我正在尝试一个基本的servlet应用程序。我创建了一个动态Web项目,并将HelloWorld.java添加到src文件夹并编辑web.xml,如下所示。然后我在服务器上运行该项目,但我得到如下错误。我在线检查了解决方案,但它没有解决我的问题..有什么帮助吗?

HelloWorld.java

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

     public class HelloWorld extends HttpServlet{ 
      public void doGet(HttpServletRequest request, 
      HttpServletResponse response)
      throws ServletException,IOException{
      response.setContentType("text/html");
      PrintWriter pw = response.getWriter();
      pw.println("<html>");
      pw.println("<head><title>Hello World</title></title>");
      pw.println("<body>");
      pw.println("<h1>Hello World</h1>");
      pw.println("</body></html>");
      }
    }

Web.xml中

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!--<!DOCTYPE web-app
     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     "http://java.sun.com/dtd/web-app_2_3.dtd"> -->

    <web-app>
     <servlet>
      <servlet-name>Hello</servlet-name>
      <servlet-class>HelloWorld</servlet-class>
     </servlet>
     <servlet-mapping>
     <servlet-name>Hello</servlet-name>
     <url-pattern>/HelloWorld</url-pattern>
     </servlet-mapping>
    </web-app>

,错误是,

Sep 23, 2013 2:38:37 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:testasu' did not find a matching property.
Sep 23, 2013 2:38:37 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:HelloWorld' did not find a matching property.
Sep 23, 2013 2:38:37 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /opt/jdk1.6.0_21/jre/lib/i386/server:/opt/jdk1.6.0_21/jre/lib/i386:/opt/jdk1.6.0_21/jre/../lib/i386:/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/xulrunner-addons:/usr/lib/xulrunner-addons:/usr/java/packages/lib/i386:/lib:/usr/lib
Sep 23, 2013 2:38:37 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Sep 23, 2013 2:38:37 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 694 ms
Sep 23, 2013 2:38:38 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Sep 23, 2013 2:38:38 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
Sep 23, 2013 2:38:38 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Sep 23, 2013 2:38:38 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Sep 23, 2013 2:38:38 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/24  config=null
Sep 23, 2013 2:38:38 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 586 ms
Sep 23, 2013 2:40:01 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet Hello as unavailable
Sep 23, 2013 2:40:01 PM org.apache.catalina.core.ApplicationContext log
SEVERE: Error loading WebappClassLoader
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@176c74b
 HelloWorld
java.lang.ClassNotFoundException: HelloWorld
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1094)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:808)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Sep 23, 2013 2:40:01 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Hello
java.lang.ClassNotFoundException: HelloWorld
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1094)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:808)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

这些类没有在WEB-INF下生成我搜索了很多关于这个问题但没有满意的答案来解决我的问题。我正在尝试使用servelets和jsp和html的很多应用程序,但这个问题的bcoz似乎没有工作..任何帮助?

2 个答案:

答案 0 :(得分:5)

清理项目后刷新项目并尝试再次部署..

答案 1 :(得分:2)

   <servlet-class>HelloWorld</servlet-class>

这是错误的。

您必须提供完全限定的名称(包裹)名称。

<servlet-class>com.some.something.HelloWorld</servlet-class>

Docs