监听器类不调用方法?

时间:2009-12-15 04:03:21

标签: java apache jsp tomcat java-ee

我正在Eclipse中开展动态Web项目。一周后点击服务器按钮中的运行,整个项目正确加载。但昨天,当我按下服务器按钮运行时,控制台会给出一条错误消息,指出它无法加载Servlet Context。服务器是Apache Tomcat 5.5,以下是控制台错误:

15 Dec, 2009 9:14:22 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Sun\SDK\jdk\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/dev/eclipse/jre/bin/client;C:/dev/eclipse/jre/bin;C:\Program Files\PC Connectivity Solution\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\Java\jre6/bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\CyberLink\Power2Go\;C:\Program Files\QuickTime\QTSystem\;C:\Sun\SDK\bin;;C:\Program Files\Common Files\Microsoft Shared\Windows Live
15 Dec, 2009 9:14:22 AM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
15 Dec, 2009 9:14:22 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 707 ms
15 Dec, 2009 9:14:22 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
15 Dec, 2009 9:14:22 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.28
15 Dec, 2009 9:14:22 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
15 Dec, 2009 9:14:23 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class InitMainMethodFromModel
java.lang.ClassNotFoundException: InitMainMethodFromModel
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3743)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
 at org.apache.catalina.core.StandardService.start(StandardService.java:448)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
15 Dec, 2009 9:14:23 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
15 Dec, 2009 9:14:23 AM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
15 Dec, 2009 9:14:23 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/BookManagementSoftwareServlet] startup failed due to previous errors
15 Dec, 2009 9:14:23 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
15 Dec, 2009 9:14:23 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
15 Dec, 2009 9:14:23 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/24  config=null
15 Dec, 2009 9:14:23 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
15 Dec, 2009 9:14:23 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 673 ms

请记住,我已经在闪存驱动器中备份了项目,之后,我尝试从头开始重新安装所有内容。其中包括Eclipse Java EE版本,Java EE,JRE,Apache Tomcat 5.5(同时尝试过.msi和.zip),并且还尝试通过创建一个名为相同但添加类和servlet文件的新项目在Eclipse中导入项目。右键单击项目并选择create new class / servlet,然后从上一个工作区的类文件中复制粘贴代码。但是我得到了和以前一样的错误。

2 个答案:

答案 0 :(得分:2)

ClassNotFoundException未提及包名称,这意味着您已将此类放在默认包中。将类放在默认包中是个坏主意。这样来自其他包(例如webserver类)的类就无法查看/导入它(自己测试:在普通包中的类内部时,尝试import默认包中的类。然而,在某些情况下,这可以在类加载和/或使用的JVM中的一些错误的帮助下工作,但你应该依赖它,它会使你的应用程序基本上不可移植。

将类放入包中。总是。还要确保在web.xml的类声明中使用完全限定的类名(包括包)。

答案 1 :(得分:1)

错误消息告诉您无法找到类InitMainMethodFromModel。你确定包含这个类的jar文件在类路径上吗?