This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

compiling command: servlet-api.jar:classes: . ?  RSS feed

 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

On p.81 of "Head First Servlets and JSP", it says to compile a servlet using this command:

% cd MyProjects/beerV1/
% javac -classpath /Users/bert/Applications2/tomcat/common/lib/
servlet-api:classes:. -d classes src/com/example/web/BeerSelect.java


What does the part:

servlet-api:classes:.

do? I looked in my Tomcat directory, and I see a file called:

servlet_api.jar


in the directory:

tomcat/common/lib

[ September 29, 2006: Message edited by: sven studde ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked in my Tomcat directory, and I see a file called:

servlet_api.jar


Not unless you renamed it. It should be left as servlet-api.jar.

The javac command should all be on one line, and the .jar suffix should be added to servlet-api.
[ September 29, 2006: Message edited by: Bear Bibeault ]
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Let me try again.

On p.81 of "Head First Servlets and JSP", it says to compile a servlet using this command:

% cd MyProjects/beerV1/
% javac -classpath /Users/bert/Applications2/tomcat/common/lib/
servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java


What does this part do:

servlet-api.jar:classes:.


I looked in my Tomcat directory, and I see a file called:

servlet-api.jar


which is in the directory:

tomcat/common/lib

[ September 30, 2006: Message edited by: sven studde ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said, it's all part of one line and is part of the classpath option.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See: http://faq.javaranch.com/view?CompilingServlets


Since this is a javac/classpath issue and not a servlet particular problem, I'm going to move this thread to the Java In General (Beginner) forum where these things are commonly discussed.
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said, it's all part of one line and is part of the classpath option.

If my question was either:

1) Is this command all one line?

or

2) Which compiling option does servlet-api.jar:classes:. belong to?


then your response would be helpful. However my question is what does this part:

servlet-api.jar:classes:.

do?

Since this is a javac/classpath issue and not a servlet particular problem


I am trying to find out what the fragment servlet-api.jar:classes:. does. In the past, I've never had to compile a servlet using that, so I'm wondering what classes are located there which are required to compile the example servlet. Although, since I've never seen colons in a classpath, there may well be javac/classpath issues involved as well.

Ok, after clicking around in your link, I understand that a colon is a Unix way of separating full paths (which corresponds to a Windows semicolon). So, I guess my question boils down to what is in the directories:

a) /tomcat/common/lib/servlet-api.jar

b) classes

c) . (current directory)

that is required to compile the servlet in the example?

I think it may have something to do with the fact that the example involves compiling from the development directory MyProjects/beerV1, which is outside of the tomcat directory. The servlet has the following import statements:

import javax.servlet.*;
import javax.servlet.http.*;
import jav.io.*;

Is the path /tomcat/common/lib/servlet-api.jar, the location of the class files referenced in those import statements?

That leaves me wondering about the classes directory and the current directory(.) in the classpath. The MyProjects/beerV1 directory has a classes directory, but it is currently empty. Compiling with the specified -d option is supposed to put the class file in the classes directory. So, why do I need to specify the classes directory in the classpath if it is currently empty?

Also, what is the point of including the current directory in the example?
[ September 30, 2006: Message edited by: sven studde ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sven,

Bear's saying "It's all one line" is a helpful answer, despite your refusal to accept it. That means that the part you're asking about in isolation is not an isolated part. The command line is this, stuck back together as it should be (your part is in bold):

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

So you see why it doesn't make sense to ask about just that part. The "servlet-api.jar" is just the end of a long path to that file, and the "classes" part is a separate classpath entry: the book assumes you want your compiled classes to go into a "classes" subdirectory of the current directory.

As for your not needing to include servlet-api.jar when compiling a servlet: I'm sorry, but you're wrong. It needs to be included. Perhaps you have your CLASSPATH environment variable set to include it -- a bad practice simply because, as in this case, it leads to things happening "magically" without your knowing why.
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest,

So you see why it doesn't make sense to ask about just that part. The "servlet-api.jar" is just the end of a long path to that file, and the "classes" part is a separate classpath entry: the book assumes you want your compiled classes to go into a "classes" subdirectory of the current directory.


It may surprise you to discover this, but I knew that before I posted. I could have posted the whole javac command on one line between code tags, but then my post would have been 3 screens wide making the thread very annoying to read.

In addition, I would think from this statement it would be clear to anyone that I understood that:

So, I guess my question boils down to what is in the directories:

a) /tomcat/common/lib/servlet-api.jar

b) classes

c) . (current directory)

that is required to compile the servlet in the example?


So you see why it doesn't make sense to ask about just that part
servlet-api.jar:classes:.


Not at all. That was the syntax that was confusing me. As I mentioned in my previous post, I discovered that the colons are full path separators in UNIX, so my question shifted to:

I guess my question boils down to what is in the directories:

a) /tomcat/common/lib/servlet-api.jar

b) classes

c) . (current directory)

that is required to compile the servlet in the example?


As for your not needing to include servlet-api.jar when compiling a servlet: I'm sorry, but you're wrong.


If you are referring to this statement:

I am trying to find out what the fragment servlet-api.jar:classes:. does. In the past, I've never had to compile a servlet using that


I can assure you that statement is quite accurate. First of all, I don't use UNIX, so compiling a servlet using colons to separate full paths wouldn't work. Secondly, there are other means to include paths than using the compiler's classpath option. Thirdly, saying that I never used that fragment before is not the same as saying it's not necessary to include servlet-api.jar to compile a servlet.

Anyway, as far as I can tell, there is nothing in the current directory or the classes directory that is referenced by the example, so those paths are unnecessary in the javac classpath option. I've just been reading some tomcat installation instructions and apparently the directory /tomcat/common/lib/servlet-api.jar contains some servlet specific classes that are referenced by servlets.

Sorry for the confusion. As a beginner, it's sometimes hard to ask questions that hit the right mark.
[ September 30, 2006: Message edited by: sven studde ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!