• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

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

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said, it's all part of one line and is part of the classpath option.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic