Eclipse does not seem to compile servlet, causing java.lang.ClassNotFoundException

 ̄綄美尐妖づ 提交于 2019-12-17 14:56:54

问题


Currently I am using Ubuntu 12.04LTS , Eclipse IDE and Apache Tomcat 7.0.27 and I am not getting the job done.

I made a simple jsp page "index.jsp" which is in "WebContent/index.jsp". I made a servlet called "EmployeeClass" which is inside the package "com.pack.web". In Jsp page I have a form with get method and a action as follow:

<form method="GET" action="hidden.do">

In web.xml I also have:

<servlet>
    <servlet-name>Searcher</servlet-name>
    <servlet-class>com.pack.web.EmployeeClass</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Searcher</servlet-name>
    <url-pattern>/hidden.do</url-pattern>
</servlet-mapping>

I made a simple servlet "EmployeeClass", it's in package:

package com.pack.web;

in this servlet I have a doGet method as:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Something is happening");
}

I finally then run my project and after hitting the submit button, bang I have this:

javax.servlet.ServletException: Error instantiating servlet class com.pack.web.EmployeeClass
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    java.lang.Thread.run(Thread.java:662)

root cause

java.lang.ClassNotFoundException: com.pack.web.EmployeeClass
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    java.lang.Thread.run(Thread.java:662)

回答1:


Finally at last after 2 weeks 15hrs and 34min I found the solution. The problem was solved by turning on automatic build which was apparently accidentally turned off.

Project -> Build Automatically



来源:https://stackoverflow.com/questions/13586475/eclipse-does-not-seem-to-compile-servlet-causing-java-lang-classnotfoundexcepti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!