Discussion:
NoClassDefFoundError: javax/servlet/http/HttpServlet
Ghodmode
2007-09-03 20:49:06 UTC
Permalink
I've had some problems loading servlets, so I tried a basic HelloWorld just
to make sure everything was working.

java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet

servlet-api.jar is in $CATALINA_HOME/lib just like it's supposed to be. All
of the example JSPs and servlets work fine.

Does anyone know what I might be doing wrong?

Apache Tomcat 6.0.14
Java 1.6.0_02-b05

Here's my HelloServlet.java:
@home:~/dev/tomcat/webapps$ cat
HelloServlet/WEB-INF/classes/mypackage/HelloServlet.java
package mypackage;

import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.*;
import java.io.*;

public class HelloServlet extends HttpServlet
{
public void doGet( HttpServletRequest req, HttpServletResponse resp
)
throws ServletException, IOException
{
PrintWriter writer = resp.getWriter();
writer.println( "<h1>Hello World</h1>" );
}
}

Here's my web.xml:
@home:~/dev/tomcat/webapps$ cat HelloServlet/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>mypackage.HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/helloservlet/*</url-pattern>
</servlet-mapping>
</web-app>

Thank you,
-- Ghodmode
David Delbecq
2007-09-03 20:55:55 UTC
Permalink
Check you didn't add servlet-api to your webapp classpath. The
servlet-api must *not* be present in WEB-INF/lib
Post by Ghodmode
I've had some problems loading servlets, so I tried a basic HelloWorld just
to make sure everything was working.
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
servlet-api.jar is in $CATALINA_HOME/lib just like it's supposed to be. All
of the example JSPs and servlets work fine.
Does anyone know what I might be doing wrong?
Apache Tomcat 6.0.14
Java 1.6.0_02-b05
@home:~/dev/tomcat/webapps$ cat
HelloServlet/WEB-INF/classes/mypackage/HelloServlet.java
package mypackage;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.*;
import java.io.*;
public class HelloServlet extends HttpServlet
{
public void doGet( HttpServletRequest req, HttpServletResponse resp
)
throws ServletException, IOException
{
PrintWriter writer = resp.getWriter();
writer.println( "&lt;h1>Hello World&lt;/h1>" );
}
}
@home:~/dev/tomcat/webapps$ cat HelloServlet/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>mypackage.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/helloservlet/*</url-pattern>
</servlet-mapping>
</web-app>
Thank you,
-- Ghodmode
---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Ghodmode
2007-09-03 21:00:29 UTC
Permalink
Thanks for your reply David.

For this servlet there's nothing in WEB-INF/lib. If it was a standalone
Java app, I guess the CLASSPATH would definitely be the first thing to
check. Is there a way to check the classpath that a servlet is using when
it's executed by Tomcat's VM?

Thank you,
Vince
Post by David Delbecq
Check you didn't add servlet-api to your webapp classpath. The
servlet-api must *not* be present in WEB-INF/lib
Post by Ghodmode
I've had some problems loading servlets, so I tried a basic HelloWorld
just
Post by Ghodmode
to make sure everything was working.
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
servlet-api.jar is in $CATALINA_HOME/lib just like it's supposed to
be. All
Post by Ghodmode
of the example JSPs and servlets work fine.
Does anyone know what I might be doing wrong?
Apache Tomcat 6.0.14
Java 1.6.0_02-b05
@home:~/dev/tomcat/webapps$ cat
HelloServlet/WEB-INF/classes/mypackage/HelloServlet.java
package mypackage;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.*;
import java.io.*;
public class HelloServlet extends HttpServlet
{
public void doGet( HttpServletRequest req, HttpServletResponse
resp
Post by Ghodmode
)
throws ServletException, IOException
{
PrintWriter writer = resp.getWriter();
writer.println( "&lt;h1>Hello World&lt;/h1>" );
}
}
@home:~/dev/tomcat/webapps$ cat HelloServlet/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>mypackage.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/helloservlet/*</url-pattern>
</servlet-mapping>
</web-app>
Thank you,
-- Ghodmode
---------------------------------------------------------------------
David Delbecq
2007-09-03 21:30:39 UTC
Permalink
Check also it's neither in shared/lib and that there is no CLASSPATH
defined (tomcat handles all by itself classpath).
Post by David Delbecq
Check you didn't add servlet-api to your webapp classpath. The
servlet-api must *not* be present in WEB-INF/lib
Post by Ghodmode
I've had some problems loading servlets, so I tried a basic
HelloWorld just
to make sure everything was working.
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
servlet-api.jar is in $CATALINA_HOME/lib just like it's supposed to be. All
of the example JSPs and servlets work fine.
Does anyone know what I might be doing wrong?
Apache Tomcat 6.0.14
Java 1.6.0_02-b05
@home:~/dev/tomcat/webapps$ cat
HelloServlet/WEB-INF/classes/mypackage/HelloServlet.java
package mypackage;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.*;
import java.io.*;
public class HelloServlet extends HttpServlet
{
public void doGet( HttpServletRequest req,
HttpServletResponse resp
)
throws ServletException, IOException
{
PrintWriter writer = resp.getWriter();
writer.println( "&lt;h1>Hello World&lt;/h1>" );
}
}
@home:~/dev/tomcat/webapps$ cat HelloServlet/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>mypackage.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/helloservlet/*</url-pattern>
</servlet-mapping>
</web-app>
Thank you,
-- Ghodmode
---------------------------------------------------------------------
---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Caldarale, Charles R
2007-09-03 21:37:13 UTC
Permalink
Subject: Re: NoClassDefFoundError: javax/servlet/http/HttpServlet
Check also it's neither in shared/lib and that there is no CLASSPATH
defined (tomcat handles all by itself classpath).
There wouldn't be a shared/lib, since this is Tomcat 6 (unless
catalina.properties has been modified). If there's an IDE being used,
it could easily have set CLASSPATH or put the servlet-api.jar in an
inappropriate place, as you suggested.

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Ghodmode
2007-09-03 22:14:09 UTC
Permalink
Post by Caldarale, Charles R
Subject: Re: NoClassDefFoundError: javax/servlet/http/HttpServlet
Check also it's neither in shared/lib and that there is no CLASSPATH
defined (tomcat handles all by itself classpath).
There wouldn't be a shared/lib, since this is Tomcat 6 (unless
catalina.properties has been modified). If there's an IDE being used,
it could easily have set CLASSPATH or put the servlet-api.jar in an
inappropriate place, as you suggested.
- Chuck
Confirmed... I don't have a shared directory.
I don't have the CLASSPATH environment variable set.

I haven't modified catalina.properties.

I was trying to use Eclipse, but that has so far proved to have more
challenges than benefits. So, I stopped.

Just to make sure I had a clean environment, I removed my tomcat directory
and untarred it again and I guess that must have fixed something. Now, the
problem has at least changed. All of the copies of HelloServlet work, but
the application I which I need to run still generates the
NoClassDefFoundError.

More to come... with a new subject line :)

Thank you for your help :)

-- Vince

Martin Gainty
2007-09-03 21:08:30 UTC
Permalink
Is servlet-api.jar in $CATALINA_HOME/common/lib

M--
---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, proprietary , confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited.
---------------------------------------------------------------------------
Le présent message électronique (y compris les pièces qui y sont annexées, le cas échéant) s'adresse au destinataire indiqué et peut contenir des renseignements de caractère privé ou confidentiel. Si vous n'êtes pas le destinataire de ce document, nous vous signalons qu'il est strictement interdit de le diffuser, de le distribuer ou de le reproduire.
----- Original Message -----
From: "Ghodmode" <***@ghodmode.com>
To: <***@tomcat.apache.org>
Sent: Monday, September 03, 2007 4:49 PM
Subject: NoClassDefFoundError: javax/servlet/http/HttpServlet
Post by Ghodmode
I've had some problems loading servlets, so I tried a basic HelloWorld just
to make sure everything was working.
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
servlet-api.jar is in $CATALINA_HOME/lib just like it's supposed to be. All
of the example JSPs and servlets work fine.
Does anyone know what I might be doing wrong?
Apache Tomcat 6.0.14
Java 1.6.0_02-b05
@home:~/dev/tomcat/webapps$ cat
HelloServlet/WEB-INF/classes/mypackage/HelloServlet.java
package mypackage;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.*;
import java.io.*;
public class HelloServlet extends HttpServlet
{
public void doGet( HttpServletRequest req, HttpServletResponse resp
)
throws ServletException, IOException
{
PrintWriter writer = resp.getWriter();
writer.println( "&lt;h1>Hello World&lt;/h1>" );
}
}
@home:~/dev/tomcat/webapps$ cat HelloServlet/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>mypackage.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/helloservlet/*</url-pattern>
</servlet-mapping>
Ghodmode
2007-09-03 21:13:09 UTC
Permalink
Post by Martin Gainty
Is servlet-api.jar in $CATALINA_HOME/common/lib
I've see reference to it on some forums, but there's no "common" directory
in my Tomcat installation.

-- Vince
Caldarale, Charles R
2007-09-03 21:18:44 UTC
Permalink
Subject: Re: NoClassDefFoundError: javax/servlet/http/HttpServlet
Is servlet-api.jar in $CATALINA_HOME/common/lib
As clearly stated by the OP, he's using Tomcat 6 and servlet-api.jar is
in $CATALINA-HOME/lib, exactly where it's supposed to be.
$CATALINA_HOME/common/lib is used only on older versions of Tomcat.

David D already pointed out the likely cause of the problem.

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Ghodmode
2007-09-03 21:38:28 UTC
Permalink
Post by Caldarale, Charles R
...
David D already pointed out the likely cause of the problem.
Post by Caldarale, Charles R
- Chuck
Unfortunately, David's idea wasn't a solution for me. There aren't any
files in my WEB-INF/lib directory.

I only created this HelloServlet to eliminate other possible causes of this
problem with more complex servlets.

One detail that I forgot to mention is that if I only add one web
application, it works fine. There's only a problem when I add more than one
application to the webapps directory. Because of this, it occurred to me
that I might somehow be causing a conflict with how I am putting the web
apps in there. However, the problem even occurs when I have two identical
HelloServlet classes which differ only in the name of the subdirectory to
the webapps folder and the name of their class.

When I try to set this up, I stop Tomcat, build the directory, compile the
class (javac -cp
~/dev/tomcat/lib/servlet-api.jarmypackage/HelloServlet.java), and
start Tomcat again. When I do this, one
always works and the others fail.

I'm not using WAR files. I'm just putting all of the files in the necessary
locations already "exploded". Is this significant?

Thank you,
Vince
Caldarale, Charles R
2007-09-03 21:43:41 UTC
Permalink
Subject: Re: NoClassDefFoundError: javax/servlet/http/HttpServlet
I'm not using WAR files. I'm just putting all of the files
in the necessary locations already "exploded". Is this significant?
Perhaps. Exactly what is your structure under webapps?

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Loading...