Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding compilation of a servlet in book HFSJ on page 81

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
iam not able to understand what this command is doing.Though i got to some extent iam not very clear about this statement


javac -classpath /...../tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java


Above i have confusion regarding the command in bold

i measn what is classes doing here?what do we mean by it?

i know the meaning of -d classes but what is classes:. doing after servlet-api.jar???
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make sense of it you need to know two things. 1) a classpath is a list directories and/or jar/zip files that contain Java class files, and 2) path entries on Unix are separated by colons. Armed with that knowledge, let's look at

There are two colons that separate the entries of the path; lets list them separately:

So there's one jar file (that contains the Servlet API), and two entries that do not look like files - so they must be directories: classes and ., which means "the current directory".

If you're using Windows instead of Unix, you'd need to use semi-colons instead of colons to separate path entries.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
classes and .

so do we really need to write these two things i means 1) classes and 2).

wont the servlet be compiled even if dont mention these 2 directories in class path?

can you please put some more light on it i.e why do we need it ?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try it without those, and see what happens?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic