File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Unable to complie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unable to complie" Watch "Unable to complie" New topic

Unable to complie

hemant chaudhary

Joined: Feb 22, 2007
Posts: 20
I am new to Servlets and JSPs.I am reading HF Servlets and JSP book so I have written my first servlet as code is given in HF on page no 30 and 31 and I have followed all steps(folder making etc).

I have made my project folder in F drive path is : F:\project1

my tomcat folder path is C:\Program Files\Apache Software Foundation\Tomcat 4.1

Now in book it is written that I need to use this command

%javac -classpath /your path/tomcat/common/lib/servlet-api.jar -d classes src/

So I m using

javac -classpath C:/Program Files/Apache Software Foundation/Tomcat 4.1/common/lib/servlet-api.jar -d classes src/

It is saying:

javac: invalid flag: Files/Apache
Usage: javac <options> <source files>
use -help for a list of possible options

but on my comp i can compile any java file.
one more thing I don't have this file(servlet-api.jar) in my lib folder of tomcat.

Please suggest a solution.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
If the classpath contains spaces it needs to be surrounded by quotes:

That servlet-api.jar is not in common/lib sounds like a problem - which libraries do you have in that directory?
[ May 27, 2007: Message edited by: Ulf Dittmer ]
Pravin Jain
Ranch Hand

Joined: May 20, 2007
Posts: 60
The problem is with the spaces in the path mentioned with the classpath switch.
pl. set CLASSPATH variable by using "<path>"
ex. -classpath "C:/Program Files/Apache Software Foundation/Tomcat 4.1/common/lib/servlet-api.jar"

This is the problem with your command line.

The Zen of Java Programming.
rahul khanna
Ranch Hand

Joined: Sep 14, 2005
Posts: 48
Spaces indeed are a problem.
Servet-api.jar should have been present by default.
What happened to that were you able to fix it ?

hemant chaudhary

Joined: Feb 22, 2007
Posts: 20
sorry for late reply.

after including quotes i was getting 5 errors:

One of them:
F:\project1>javac -classpath "C:/Program Files/Apache Software Foundation/Tomcat
4.1/common/lib/servlet-api.jar" -d classes src/
src\ package javax.servlet does not exist
import javax.servlet.*;


Then I changed sevlet-api.jar to servlet.jar(this one is ther ein lib directory) and now it is working

Thanks to all you people for replying.

I agree. Here's the link:
subject: Unable to complie
It's not a secret anymore!