• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mistakes in HFSJ

 
Patrick Beck
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Patrick Beck
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah ok, dont know much about windows and I think it isnt mentioned in HFSJ
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic