It's not a secret anymore!
The moose likes Beginning Java and the fly likes Classpath in Command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classpath in Command line" Watch "Classpath in Command line" New topic

Classpath in Command line

Nelo Angelo
Ranch Hand

Joined: Jul 25, 2011
Posts: 44

Hello everyone,

I was going through Head First Servlets book and found myself stuck in the example.


To compile the servlet following code is being used:
% javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/

I am using Windows XP and my Tomcat directory's path is this:
C:/Program Files/Apache Software Foundation/Tomcat 5.5/common/lib;

So I am using this code in the command prompt to compile, but it generates an error:
C:\beerV1>javac -classpath /Program Files/Apache Software Foundation/Tomcat 5.5/common/lib//servlet-api.jar:classes:. -d classes src/com/example/web/

javac: invalid flag: Files/Apache
Usage: javac <options> <source files>

I love java but she hates me... :'(
arvind kushwaha
Ranch Hand

Joined: Aug 12, 2011
Posts: 32
set the classpath for your program. For eg.

c:> set classpath=.;Here provide the path of your servlet-api-jar; %z%;
Nelo Angelo
Ranch Hand

Joined: Jul 25, 2011
Posts: 44

Thanks for the replies, but I want to know how the above given code can be modified to be used in Windows. The compound statement that sets the classpath as well as compiles the code.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46362
You would appear to have misread the previous post, which uses a Windows® idiom.
Yoiur question is not at all clear. Do you mean this
javac -cp .;c:\MyFolder\MyOtherFolder\MyJar.jar
Shankh Pani Parimal

Joined: Dec 29, 2011
Posts: 8

Nelo Angelo
Ranch Hand

Joined: Jul 25, 2011
Posts: 44

Thanks for the reply guys, the problem is resolved.

I used the following code:

C:\beerV1>javac -cp C:\Tomcat_6.0\lib\servlet-api.jar; -d classes src/com/example/web/
I agree. Here's the link:
subject: Classpath in Command line
It's not a secret anymore!