我的 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"]