Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problems when reading Head.First.Servlets.and.JSP.2nd.Edition  RSS feed

 
Alexander Cheng
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I am reading Head.First.Servlets.and.JSP.2nd.Edition. I came accross some problems. The example in the third chapter, that is the servlet version two(
% cd beerV1
% javac -classpath /Users/bert/Applications2/tomcat/common/lib/
servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java
here exactly),
although I did everything you told in the book but it returns the error that the com.example.model doesn't exist. I have set my classpath(.;c:\jdk1.6.0_02\lib\tools.jar;c:\jdk1.6.0_02\lib\dt.jar) and path (bin). And the directory tree is like src\com\example\model. I have referred to many friends but they didn't find out what was wrong either.So I want to see if you can give me some light on this.

By the way my jdk is 1.6.0_04 and my tomcat version is 5.5.

Looking forward to hear from you soon.
 
Vijitha Kumara
Saloon Keeper
Posts: 3998
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your "BeerSelect.java" depends on "com.example.model" ? If so that should be in the classpath too. Apparently you are in a directory which has "src/com/example/web/BeerSelect.java" ? Instead of specifying just "classes" as the classpath you should give it the absolute/relative path (if classes dir contains compiled com.example.model). You may post more details about your directory structure etc.. so we can help if this doesn't. And Welcome to Javaranch

 
Alexander Cheng
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,Thanks for your rapid reply.
This is the structure of my directory. I have E:\MyProjects\beerv1\src\com\example\web\BeerSelect.java and E:\MyProjects\beerv1\src\com\example\model\BeerExpert.java. The classes are in the directory E:\MyProjects\beerv1\classes\com\example\model\BeerExpert.class and E:\MyProjects\beerv1\classes\com\example\web\BeerSelect.class. I didn't copy them into the tomcat directory though , cause I can't compile them . It is the second version of BeerSelect.class, that is the one that seperates the bussiness logic from the servlet, so it is necessary to include the BeerExpert.class package.
I have complied the BeerExpert.class, although with some warnings but I get the class. The warnings are something like I am using an old version.
And I am stuck at the point of compiling BeerSelect.class just as I mentioned before. So could you give me some suggestions?
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess, for the -classpath option you should also provide the com.example.model package which you can do by mentioning till E:\MyProjects\beerv1\src\.
separate multiple values with ";" on winOS and ":" on UNIX.
 
Vijitha Kumara
Saloon Keeper
Posts: 3998
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alexander Cheng wrote:The classes are in the directory E:\MyProjects\beerv1\classes\com\example\model\BeerExpert.class and E:\MyProjects\beerv1\classes\com\example\web\BeerSelect.class....


When you compile give the classpath as "E:\MyProjects\beerv1\classes" then the classes already compiled which are needed to compile the servlet will be picked up. And have the "-d E:\MyProjects\beerv1\classes "switch as well so the compiled code will be placed in the appropriate structure.
 
Campbell Ritchie
Marshal
Posts: 55741
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to servlets forum.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Moving to servlets forum.

Ummm... I think this is more related to plain java than servlets.
 
Alexander Cheng
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himanshu Kansal wrote:I guess, for the -classpath option you should also provide the com.example.model package which you can do by mentioning till E:\MyProjects\beerv1\src\.
separate multiple values with ";" on winOS and ":" on UNIX.


Do you mean that I should add the E:\MyProjects\beerv1\src\. like the one I add the java bin ? I will try, but in this way, every time I include a new package I have to reset the classpath.
 
Alexander Cheng
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijitha Kumara wrote:
Alexander Cheng wrote:The classes are in the directory E:\MyProjects\beerv1\classes\com\example\model\BeerExpert.class and E:\MyProjects\beerv1\classes\com\example\web\BeerSelect.class....


When you compile give the classpath as "E:\MyProjects\beerv1\classes" then the classes already compiled which are needed to compile the servlet will be picked up. And have the "-d E:\MyProjects\beerv1\classes "switch as well so the compiled code will be placed in the appropriate structure.


Is it like this?
% javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar;e:/MyProjects/beerv1/classes
;classes:. -d classes src/com/example/web/BeerSelect.java


OK ,I tested it and got passed. Thank you all very much.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!