9

我的 Java servlet 似乎在抱怨它找不到包中包含的文件(marktest)。我使用 Eclipse (Indigo) 开发和 Tomcat7。

这是错误:

SEVERE: Error configuring application listener of class marktest.Config
java.lang.ClassNotFoundException: marktest.Config
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

这是 Config.java,其中包含实现 ServletContextListener 的类,它说它在错误中找不到:

package marktest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


public class Config implements ServletContextListener 
{

    private ExecutorService executor;

    @Override
    public void contextInitialized(ServletContextEvent event) 
    {
        System.out.println("########################## ServletContextListener started ###############################");

    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
    }

}

这是 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>de.vogella.jersey.first</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>marktest</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

    <listener>
        <listener-class>marktest.Config</listener-class>
    </listener>

</web-app> 

即使经过大量谷歌搜索,我也很困惑。在此先感谢您的帮助。

标记

- - 编辑 - -

以下是完整的控制台日志

10-Jan-2013 15:45:18 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:nlpServer' did not find a matching property.
10-Jan-2013 15:45:18 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:18 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 661 ms
10-Jan-2013 15:45:18 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
10-Jan-2013 15:45:18 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.21
########################## ServletContextListener started ###############################
10-Jan-2013 15:45:19 org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [1,052] milliseconds.
10-Jan-2013 15:45:19 com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  marktest
10-Jan-2013 15:45:19 com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class marktest.hello
10-Jan-2013 15:45:19 com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
10-Jan-2013 15:45:19 com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.16 11/28/2012 02:09 PM'
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class marktest.Config
java.lang.ClassNotFoundException: marktest.Config
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors
10-Jan-2013 15:45:20 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:20 org.apache.catalina.startup.Catalina start
INFO: Server startup in 2538 ms
10-Jan-2013 15:45:24 org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
10-Jan-2013 15:45:24 org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:25 org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
10-Jan-2013 15:45:25 org.apache.catalina.util.LifecycleBase stop
INFO: The stop() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] after stop() had already been called. The second call will be ignored.
10-Jan-2013 15:45:25 org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:25 org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]
4

4 回答 4

13

在我看来,好像您的类没有通过 WTP 正确部署到 Tomcat(再次清理/发布)。

于 2013-02-24T19:24:27.443 回答
1

即使我ClassNotFoundException之前在给定快照中突出显示的在 tomcat 服务器 web.xml 中配置的侦听器类条目时也得到了相同的结果 - Eclipse 项目配置快照

收到此错误后,我已将同一条目从 tomcat config Web.xml替换 为 {Project_Path}/WebContent/WEB-INF/web.xml。

发布错误在tomcat服务器启动时解决。

于 2020-07-25T15:12:10.400 回答
0

这个问题可以关闭,结果发现eclipse有问题并且没有发布我的更改。

于 2013-02-23T15:58:49.757 回答
0

导致删除库源或在构建路径中移动一个。确保在构建路径 > 库中没有任何遗漏的库。

清理项目并再次运行tomcat。这会有所帮助。

于 2015-07-18T21:43:16.110 回答