File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem compiling a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem compiling a servlet" Watch "Problem compiling a servlet" New topic

Problem compiling a servlet

Paulo Crestani

Joined: Nov 06, 2007
Posts: 19

I am very begginer with servlets and I am having trouble to compile my servlet class. For those who follow the Head First book, it is the example of chapter 3.

The problem is that the javac can not find the servlet classes like HttpServlet, HttpServletRequest and HttpServletResponse. In the book the authors use classpath to direct javac to the proper directory where to find the classes and in that example, the classes are under .../tomcat/commom/lib

I am working with Tomcat 6 and I did not find a dir .../tomcat/commom/lib. There is a ...\Tomcat 6.0\lib and I suppose it is this one, but it is under "Program Files" and javac is complaining about the blancs in the dir name. Is there a way to solve this?


Paulo Crestani.
Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
For names with blanks (like "Program Files"), replace the 7th-Nth characters with ~1 ("Progra~1").

Hope this helps.

SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Compiling Servlets

[My Blog]
All roads lead to JavaRanch
Roberto Perillo

Joined: Dec 28, 2007
Posts: 2271

Howdy, Paulo.

Man, you need to add the servlet-api.jar file to your classpath.
Try adding the file path between double quotes in the command line. For example:

javac -cp "C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar"

Give it a try. Hope this helps!

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Paulo Crestani

Joined: Nov 06, 2007
Posts: 19
Great thanks,

It works now! Guys I am sorry for posting such a naive question in this forum.

Now I noticed that there is another forum specially for Servlets on Java Ranch and I will stay on that one until I upgrade my level on Servlets so I can try SCWCD.

Thank you.
I agree. Here's the link:
subject: Problem compiling a servlet
It's not a secret anymore!