• 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
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Command line arguments

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

I have a problem regarding command line arguments from the Head First JSP.

I am referencing pg 81 Compiling the servlet

%cd MyProjects/beerV1

%javac -classpath /Users/bert/Applications2/comman/lib/servlet-api.jar
:classes:. -d classes src/com/exampl/web/BeerSelect.java

I fail to understand the the command highlighted in bold above ":classes:.".

When I tried to compile using the above command I got errors such as'cannot find HttpServlet'.

Therefore I removed the ':classes:.' ,and than it compiled fine.

My question is that I dont understand what the ':classes' command does and what effect it will have on the compilation of my code.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abdulla,

I'm stumped on why removing ":classes:." would cause that type of error. If you're thinking of ":classes:." as a command/flag tho that would be wrong. It's just more path info for the -classpath flag. Make sure there are no spaces between ":classes:." and the path info preceding it ".../servlet-api.jar". I say that because if you're thinking of it as a command you might have put a space there

Tobin
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Okay, I got the point that :classes:. is not a command.

Is :classes:. a subfile in the servlet-api jar ?
How does the '.' operator function in this case ?

I am still getting the same error with :classes:.
Also when I try to compile the code on pg84, I get an error stating that the compiler cannot find the package 'com.example.model'
 
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Abdulla,

The javac command takes source files and compiles them into .class files, as you probably know. The basic form of the command is:


The -classpath option provides one or more JAR files or directories that contain .class files that the source file depends upon. Therefore, the command:

tells the compiler to use the servlet API JAR file and the classes directory (a subdirectory of the directory from which you invoked the javac command) while compiling the source file. The : (colon) character is used to separate multiple JAR files or directories. Also note that the . (dot) character tells the compiler to look for classes in the current directory.

The -d option tells the compiler where to store the new .class files generated by compiling the source file.

Does that help?

-Bryan
[ September 13, 2004: Message edited by: Bryan Basham ]
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Bryan for giving such a detailed explanation.
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

When I try to compile CoffeeSelect from pg 85 of HF JSP,I am getting the following error messages.

--------------------------------------------------------------------------
C:\MyProject\coffeeV1>javac -classpath /tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/CoffeeSelect.java

src/com/example/web/CoffeeSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src/com/example/web/CoffeeSelect.java:4: package javax.servlet does not exist
import javax.servlet.*;
^
src/com/example/web/CoffeeSelect.java:5: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
src/com/example/web/CoffeeSelect.java:9: cannot resolve symbol
symbol : class HttpServlet
location: class com.example.web.CoffeeSelect
public class CoffeeSelect extends HttpServlet {
^
src/com/example/web/CoffeeSelect.java:11: cannot resolve symbol
symbol : class HttpServletRequest
location: class com.example.web.CoffeeSelect
public void doPost(HttpServletRequest request, HttpServletResponse respo
nse)
^
src/com/example/web/CoffeeSelect.java:11: cannot resolve symbol
symbol : class HttpServletResponse
location: class com.example.web.CoffeeSelect
public void doPost(HttpServletRequest request, HttpServletResponse respo
nse)
^
src/com/example/web/CoffeeSelect.java:12: cannot resolve symbol
symbol : class ServletException
location: class com.example.web.CoffeeSelect
throws IOException, ServletException {
^
src/com/example/web/CoffeeSelect.java:20: cannot resolve symbol
symbol : class CoffeeExpert
location: class com.example.web.CoffeeSelect
CoffeeExpert be=new CoffeeExpert();
^
src/com/example/web/CoffeeSelect.java:20: cannot resolve symbol
symbol : class CoffeeExpert
location: class com.example.web.CoffeeSelect
CoffeeExpert be=new CoffeeExpert();
^
9 errors

------------------------------------------------------------------------

Please, closely take note of the two errors that are highlighted.

Firstly, it cannot find my model package in which my CoffeeExpert sits.
Secondly, it cannot locate my javax.servlet.

I have installed Tomcat 5.xxx it has the servlet-api jar file. The model package has been setup and coded according to the book. There is no problem with the code I have cross checked several times.

I fail to understand the cause of the above two problems.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to fix the "package javax.servlet does not exist" error by adding j2ee.jar to my classpath. I am also getting "package com.example.model does not exist" and I'm stumped.

This is what I am doing:
C:\dev\MyProjects\beerV1> javac -classpath c:\dev\tomcat\common\lib\servlet-api.jar:classes:.;c:\j2sdkee1.3.1\lib\j2ee.jar -d classes src/com/example/web/BeerSelect.java

There must be something else I have to add to the classpath, but I don't know what.
 
Amy Humphries
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This worked for me:

javac -classpath c:\dev\tomcat\common\lib\servlet-api.jar:classes:.;c:\j2sdkee1.3.1\lib\j2ee.jar;c:\dev\MyProjects\beerV1\classes -d classes src/com/example/web/BeerSelect.java
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amy Humphries:
This worked for me:

javac -classpath c:\dev\tomcat\common\lib\servlet-api.jar:classes:.;c:\j2sdkee1.3.1\lib\j2ee.jar;c:\dev\MyProjects\beerV1\classes -d classes src/com/example/web/BeerSelect.java




To make things even clearer for Java-newbies that have never installed the SDK and/or have never compiled Java from the command-line (like me !), it seems that the windows version of the SDK requires SEMICOLONS instead of colons to separate the class files in the -classpath argument.

The book says to use

-classpath .../servlet-api.jar:classes:.

On Windows (XP ?), using that will result in "package javax.servlet does not exist" and other errors.

Using instead :

-classpath .../servlet-api.jar;classes;.

will work just fine (for me anyway).

Thus no need for the j2ee sdk classes, the point is that all needed classes are in the tomcat/common/lib directory.

(this must have been posted a zillion times across all forums)...

Does that qualify as a book errata ?
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I managed to compile the Java file now but I don't understand why it is working now.

Someone tried to explain in detail what the commandline meant but I'm still confused.
This is what i typed in:

E:\Java\Servlets_JSP\Beer-v>javac -classpath d:/jakarta/common/lib/servlet-
api.jar;classes;. -d classes src/com/example/web/beerSelect.java

Why do I have to set the classpath , isn't that what I did as an environment variable???
I have CLASSPATH = D:\jakarta\common\lib\servlet-api.jar
Do I override the classpath and add the classes or what is really going on here?

what is in this 'classes' and why is it needed? servlet-
api.jar;classes;.

I could compile everything before, following the examples in the book, but when I needed to import the package com.example.model it didn't work anymore.

Anyone knows...???
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys
Simplest solution to your problems can be add servlet.jar (or servlet-api.jar) and anyother required packages to your classpath.

Another reason of your problems I can see is that there is a differnce in providing classpath on command line in winodws and unix(unix like) systems. command provided in book seems to be good for unix (and its clones). Consult your respective os on how to provide classpath on command lines. Hope this helps.

Regards
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Patrik,

To answer your question about ;classes;

classes is the name of the directory that your compiled classes code has been put, based on the "-d classes" flag you are using for the javac command line. ("-d" says "put compiled classes in the following directory").
By having "classes" in the classpath, the java compiler can find the other classes you may have compiled so far. Keep in view that since there is no "/" in front of classes, the compiler will look for the directory from the directory you invoke it from.
i.e. you should be able to successfully "cd classes" from where you run the javac command!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, everybody.

To solve the problem "javax.servlet.*; does not exist" I did the following:

I copied the file servlet-api.jar from ...\Tomcat 5.5\common\lib to
the directory jdk/jre/lib/ext/

It's work very well!
 
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any tool to compile servlet and JSP through well GUI?
 
Author
Posts: 144
5
jQuery Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
netbeans or eclipse are some very good gui's to run these examples through.
 
please buy my thing and then I'll have more money:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic