wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Mistakes in HFSJ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Mistakes in HFSJ" Watch "Mistakes in HFSJ" New topic
Author

Mistakes in HFSJ

Patrick Beck
Ranch Hand

Joined: Nov 07, 2006
Posts: 82
Hi together,

I'm currently studying with HFSJ to prepare for SCWCD. I thought about writing down any errors I find in the book (NOT listet in Errata) while working with the examples:

Configuration: WinXP, Tomcat 5.5.20, Java 1.5.0_09

Page: 81
HFSJ says for compiling the servlet:
javac -classpath /Users/bert/.../lib/servlet-api.jar:classes:. -d classes...


C:\Dokumente und Einstellungen\ds\Desktop\MyProjects\beerV1>C:\Programme\Java\jd
k1.5.0_08\bin\javac -classpath C:\Programme\apache-tomcat-5.5.20\apache-tomcat-5
.5.20\common\lib\servlet-api.jar:classes:. -d classes src\com\example\web\BeerSe
lect.java
src\com\example\web\BeerSelect.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
src\com\example\web\BeerSelect.java:4: package javax.servlet.http does not exist

import javax.servlet.http.*;
^
src\com\example\web\BeerSelect.java:7: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet {
^
src\com\example\web\BeerSelect.java:8: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request, HttpServletResponse respo
nse) throws IOException, ServletException {
^
src\com\example\web\BeerSelect.java:8: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request, HttpServletResponse respo
nse) throws IOException, ServletException {
^
src\com\example\web\BeerSelect.java:8: cannot find symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request, HttpServletResponse respo
nse) throws IOException, ServletException {

^
6 errors


It works if I leave that :classes:. away:

C:\Dokumente und Einstellungen\ds\Desktop\MyProjects\beerV1>C:\Programme\Java\jd
k1.5.0_08\bin\javac -classpath C:\Programme\apache-tomcat-5.5.20\apache-tomcat-5
.5.20\common\lib\servlet-api.jar -d classes src\com\example\web\BeerSelect.java


Page: 82
Compiles with warnings:

C:\Dokumente und Einstellungen\ds\Desktop\MyProjects\beerV1>C:\Programme\Java\jd
k1.5.0_08\bin\javac -d classes src\com\example\model\BeerExpert.java
Note: src\com\example\model\BeerExpert.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

[ November 20, 2006: Message edited by: Patrick Beck ]

SCJP5<br />SCWCD<br />SCBCD (preparing)<br />IBM/Lotus CLS, CLP, PCLP R5/R6/R7<br />LPIC-1, LPIC-2
Patrick Beck
Ranch Hand

Joined: Nov 07, 2006
Posts: 82
Now I got an error on page 85 saying that package com.example.model would not exist. But it exists and contains BeerExpert.class


C:\Dokumente und Einstellungen\ds\Desktop\MyProjects\beerV1>C:\Programme\Java\jd
k1.5.0_08\bin\javac -classpath C:\Programme\apache-tomcat-5.5.20\apache-tomcat-5
.5.20\common\lib\servlet-api.jar -d classes src\com\example\web\BeerSelect.java
src\com\example\web\BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src\com\example\web\BeerSelect.java:16: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
src\com\example\web\BeerSelect.java:16: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors


Couldn't find out where the mistake is... code is exactly as in HFSJ.
Any ideas?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

It works if I leave that :classes:. away:

You don't have to leave it away, you have to separate each directory with semi-colons ( , not colons(


[My Blog]
All roads lead to JavaRanch
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
the javac -d option is indeed a good way to make your claases fall in the appropriate directories, but the simplest and the most easeist (at least i use it )way is -

copy you servlet source files to the JDK_dir/bin folder , compile the files there, copy the class files to the desired direcotyr in tomcat, and its done.

of course the servlet jsr should be in the classpath


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

copy you servlet source files to the JDK_dir/bin folder , compile the files there, copy the class files to the desired direcotyr in tomcat, and its done.

Not the best piece of advice to hear from a SCJP owner
I would not recommend to put anything in the JDK's bin directory.
Learn how to use the classpath for once, and then you'll be able to do anything anywhere.
[ November 20, 2006: Message edited by: Satou kurinosuke ]
Patrick Beck
Ranch Hand

Joined: Nov 07, 2006
Posts: 82
I tried it again with GNU/Linux and now it works. Also that :classes:. thing works. I better use GNU/Linux while working with HFSJ (and tomcat).

Thanks for help!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I better use GNU/Linux while working with HFSJ (and tomcat).

No, you'd better learn more about the CLASSPATH

In unix, the separator is colon, but in windows, it's semi-colon.
Patrick Beck
Ranch Hand

Joined: Nov 07, 2006
Posts: 82
ah ok, dont know much about windows and I think it isnt mentioned in HFSJ
Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
Yeah...thats because in HFSJ all the screenshots shown are MAC-OS screenshots....I presume they've(Bates & co.) worked on a MAC (MAC OS is UNIX based)...that's why they've used colons : ...even the Tomcat startup command they've used is startup.sh....


Turn on, tune in, drop out.
 
jQuery in Action, 2nd edition
 
subject: Mistakes in HFSJ
 
Similar Threads
Still cant complile servlet after setting classpath
package does not exist problem
Compiling servlets
Problem to compile servlet and Tomcat
How To Compile Servlet