views:

65

answers:

2

I'm working on a Dynamic Web Project in Eclipse. The whole project was loading properly upon clicking the run in server button, a week back. But yesterday, when I pressed the run in server button, the console would give an error message stating that it can't load the Servlet Context. The server is Apache Tomcat 5.5 and the following is the console error :

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

Bear in mind that I already had the project backed up in a flash drive, following which, I tried reinstalling everything from scratch. Which includes Eclipse Java EE version, Java EE, JRE, Apache Tomcat 5.5(tried both, .msi and .zip) and, also tried importing the project in Eclipse by creating a new project entitled the same but adding the class and servlet files by right-clicking the project and choosing the create new class/servlet and, copy-pasting the code from the class files of the previous workspace. However I get the same error as before.

+1  A: 

The error message is telling you that class InitMainMethodFromModel cannot be found. Are you sure the jar file containing this class is on the classpath?

Jim Garrison
In fact I wrote the `InitMainMethodFromModel` Listener class. It implements the `ServletContextListener`
Catfish
Well, the message says it can't find the class. Start from there and try to figure out why.
Jim Garrison
Well, as it is written in the console, the problem ends here: `org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) 15 Dec, 2009` . Hence, even you can see the problem
Catfish
Like I earlier mentioned, the whole project was working fine a week ago, when I checked the last time.
Catfish
+1  A: 

The ClassNotFoundException didn't mention the package name, what thus means that you've placed this class in the default package. Putting classes in the default package is a bad idea. This way the classes from other packages (such as the webserver classes) cannot see/import it (test it yourself: try to import a class from the default package when inside a class in a normal package). There are however certain circumstances where this is got to work with a little help of hacks in the classloading and/or a bug in the JVM used, but you should really not rely on it, it makes your application basically unportable.

Put classes in a package. Always. Also ensure that you're using full qualified classnames (including package) in the class declarations in web.xml.

BalusC
Thanks for the pointer, it wasn't necessarily that I used default packages, but that, the fully qualified name didn't register in the deployment descriptor when I added the `package [fully qualified name]` into the class
Catfish