Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse/tomcat: deploy doesn't work any more (ClassNotFoundException)

Tags:

I'm running Eclipse Helios Service Release 1, with Tomcat 7.0.12 in Linux Ubuntu Natty Narwhal.

I've been happily hot re-deploying my webapp until it stopped working for apparently no reason. The following exception is displayed:

SEVERE: Allocate exception for servlet Index java.lang.ClassNotFoundException: obliquid.servlet.Index     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521) 
  • In Servers tab I've "Tomcat v7.0 Server at localhost [Started,Synchronized]
  • My project appears as a child of Tomcat v7.0 Server
  • In Properties, Java Build Path, Source I've Project/src Source folder
  • In Properties, Web Deployment Assembly, I've the following mappings: /WebContent -> /, /src -> /WEB-INF/classes, /test -> /build/classes
  • My src directory contains a Servlet in obliquid/servlet/Index.java
  • I tried already to click on Clean Module Work Directory... and Publish
  • I tried to stop and start the Server from within Eclipse Servers tab

What else should I check? Thank you.

UPDATE Despite now I'm working with the new project, I came back to check the old one, and mysteriously now it's working. I think I won't be able to find what has happened.

However today with the new project, I had 404 errors with no apparent reason and I found out that right clicking on the Tomcat server and selecting "Clean..." can be useful. Maybe it could have helped.

Selecting "Clean..." says: "Clean will discard all publish state and republish from scratch. Are you sure you want to clean all published resources?". Selecting yes, I solved the problem

UPDATE 2 It happened again on the new project. 404 errors, this time they don't go away.

Stop -> Clean... -> Start (404) Stop -> Clean Tomcat Work Directory... -> Start (404) Stop -> Clean Tomcat Work Directory... -> Clean... -> Start (404) Stop -> Remove on the application ->  Clean... -> Run As -> Run on Server -> (404)   Exit Eclipse, Start Eclipse Start the server -> (404) 

UPDATE 3 It turned out that this time I just didn't notice an exception caused by a listener-class during startup. After solving the problem, it worked. Guess I should stop working at 3 AM.

like image 237
stivlo Avatar asked May 09 '11 09:05

stivlo


People also ask

What should be deploy path for Tomcat?

A web application can be deployed in Tomcat by one of the following approaches: Copy unpacked directory hierarchy into a subdirectory in directory $CATALINA_BASE/webapps/ . Tomcat will assign a context path to your application based on the subdirectory name you choose. We will use this technique in the build.

Do we need to deploy jar file in Tomcat?

Apache tomcat is a web container you cannot deploy a jar in tomcat server. If you created a web application then export your application as war file and put it in tomcat webapp directory, start the server and your war will be deployed.

Can we deploy more than one war in Tomcat?

Simply drop both war files into Tomcat's webapps folder. That is all you need to do. By default, Tomcat expands ("explodes" some say) each war (technically a zip file) into a folder and automatically deploys the app for you. This happens on the fly if Tomcat is already running, or on startup when you launch Tomcat.


2 Answers

While on Tomcat 6 and Eclipse Ganymede I found out the following chain to work like charm:

1 stop server

2 project -> clean

3 project build (I had automatic build disabled)

4 delete server

5 delete Servers folder

6 restart Eclipse

7 create new server, add project and start :)

takes some time but worked like charm. My problem was a irritating Listener start problem, but this seems to be something similar: a property at tomcat. Btw: nowadays I am also a big Glassfish fan.

like image 156
mico Avatar answered Sep 29 '22 13:09

mico


I found that this procedure is useful:

  • Click on Servers tab and Stop the server in use if it's running
  • Right click on the server again and select Clean...
  • Right click again and select Clean Tomcat Work Directory...

Hopefully the ClassNotFoundException should be gone now.

Another time I had a problem with a class launched at server startup, an exception in a listener class (ServletContextListener). When a ServletContextListener raises an exception during startup the application deployment is aborted, hence the 404 errors. In that case fixing the problem that caused the exception, made the application working again.

EDIT: This shorter procedure worked for me most of the times, but today didn't work and I had to follow Mico's extended procedure. My suggestion is, if you have a similar problem, first try this shorter procedure. If the problem persists, try with Mico's.

like image 42
stivlo Avatar answered Sep 29 '22 15:09

stivlo