Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError: HttpServlet

 
Vince Aggrippino
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Apache Tomcat 6.0.14 with Java 1.6.0_02.

I've been having some trouble loading servlets, so I tried a basic HelloWorld type program just to make sure everything was okay and it can't find the servlet-api.jar.

I'm getting NoClassDefFoundError: javax/servlet/http/HttpServlet

Isn't it supposed to automatically load all of the jar files in $CATALINA_HOME/lib?

Here's my code:

Here's my web.xml:

Thank you,

--
-- Vince
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


All classes used in servlets should be in a package - thats the first thing to correct.

If Tomcat runs and you can execute the example servlet and JSPs provided then your installation has all it needs.

Bill
 
Vince Aggrippino
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:


All classes used in servlets should be in a package - thats the first thing to correct.

If Tomcat runs and you can execute the example servlet and JSPs provided then your installation has all it needs.

Bill

I realize that all classes used in servlets should be in a package as a matter of convention and good programming practice. As you might have guessed, all of my other servlets have packages. However it's not an error not to use a package.

I added a package to my test servlet, recompiled, and restarted Tomcat, but there was no change.

Tomcat runs and I can run all of the example servlets and JSPs provided.

I did notice that I don't have the problem if I'm only attempting to load a single servlet with Tomcat. If I only add one web application to the webapps folder, it runs fine.
[ September 03, 2007: Message edited by: Vince Aggrippino ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vince Aggrippino:

I realize that all classes used in servlets should be in a package as a matter of convention and good programming practice. As you might have guessed, all of my other servlets have packages. However it's not an error not to use a package.


That's not entirely correct.
There are times when the container will not be able to find classes that are not packaged. This is not one of them but, if your having trouble getting something to work, you should start buy ruling this problem out.
You can read more about this here:
http://faq.javaranch.com/java/PackageYourBeans
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have j2ee.jar in your JDK directory anywhere do you?
I've heard of people having trouble with Tomcat when they do.
 
Vince Aggrippino
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
You don't have j2ee.jar in your JDK directory anywhere do you?
I've heard of people having trouble with Tomcat when they do.


No, I don't. I was hoping that was the solution

I have made a little progress...
I deleted my tomcat installation directory and untarred it again and now basic HelloWorld type servlets will run. I'm not getting a NoClassDefFound error for HttpServlet any more, but I'm still getting the problem and I think it's related.

I'll post a new thread with a new subject.

Thank you,
Vince
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However it's not an error not to use a package.


Wow what an amazing statement! It is true that Tomcat will not raise an error when it sees that in a web.xml statement - probably a consequence of the dreaded invoker servlet use in early versions.

Hard to figure out errors due to the package thing are the base of a large fraction of beginner problems fielded here at the ranch. Just grit your teeth, bite the bullet etc etc and put all classes used in servlets in a package.

Bill
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but I'm still getting the problem and I think it's related.


What problem are you seeing now?
 
Vince Aggrippino
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:


What problem are you seeing now?


Thank you, Ben. I think I figured it out.

The problem seemed intermittent and now I know why. It depended on what directory I was in when I started Tomcat.

I wanted to save myself some typing, so I made symbolic links to $CATALINA_HOME/bin/startup.sh and $CATALINA_HOME/shutdown.sh and put them in ~/bin, which I've added to my path.

I know there is some code in those shell scripts to detect if the command that called it is a symbolic link and take appropriate actions based on that, but I guess it doesn't work perfectly.

I've changed my symlinks to actual scripts, with two lines each. Change to the Tomcat directory, then run startup.sh/shutdown.sh. Now everything works fine every time

Thank you all for your time and consideration.

-- Vince
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad it's working.
Thanks for posting back with your solution.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic