aspose file tools*
The moose likes Beginning Java and the fly likes cannot compile servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot compile servlet" Watch "cannot compile servlet" New topic
Author

cannot compile servlet

Ravi Gupta
Ranch Hand

Joined: Jul 15, 2006
Posts: 38
Hi

I am unable to run the servlet version 2 given on page 85(of Head First Servlets and JSP 2nd edition) even after building the directory structures as shown in the book. Specifically, i am unable to compile the servlet called BeerSelect.java. The error shown is "unable to find package com.example.model.*". I have checked and rechecked the directory structures. I am compiling the servlet from MyProjects/beerV1 directory with the command "javac -d classes src/com/example/web/BeerSelect.java" as i have already set the classpath elsewhere. Moreover version 1 of the same servlet is running fine.

Also i would like to report that the deployment descriptor given on page 30 in chapter 1 of the same book does not work well. Tomcat 5.5 shows error in the first line of the web.xml file i.e. "<?xml version=�1.0� encoding=�ISO-8851-1� ?>". Upon removing this line the servlet runs fine.

Please help guys.


help your PC help you best
http://simplepccare.spaces.live.com
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi ravi,

1.did you set servlet-api.jar on classpath?

2.which version of tomcat you are using?

Hope This Helps
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by seetharaman venkatasamy:
Hi ravi,

2.which version of tomcat you are using?




sorry, your using tomcat5.5 ...then try this web.xml and put it into the WEB-INF directory


try and let me know
[ August 07, 2008: Message edited by: Ulf Dittmer ]
Ravi Gupta
Ranch Hand

Joined: Jul 15, 2006
Posts: 38
I have copied servlet-api.jar and jsp-api.jar files in the C:\Program Files\Java\jdk1.5\jre\lib\ext directory. This serves the same purpose. Moreover, rest examples are running fine i.e. chapter1,2,3.The problem is with this one only.
jaimin gohel
Greenhorn

Joined: Jul 30, 2008
Posts: 13
well it seems that you are putting your .java files and .class files in different directories.

so in your case you have to make sure that the package "com.example.model" is in the both directories.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

You said that you are compiling like this:
"javac -d classes src/com/example/web/BeerSelect.java"
So the directory you are in must look like this:
MyProjects/beerV1/src/com/example/web/BeerSelect.java
BeerSelect.java must try to import "com.example.model.*" which is probably found at:
MyProjects/beerV1/src/com/example/model/
The problem is that com.example.model is NOT in your classpath. Your classpath begins in the MyProjects/beerV1/ directory (because that is where you are when you run the javac command) and the package is in the MyProjects/beerV1/src/ directory.

Try running javac from inside the MyProjects/beerV1/src/ directory and compile with:
"javac -d classes com/example/web/BeerSelect.java"

That should fix the problem.
[ August 07, 2008: Message edited by: Steve Luke ]

Steve
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Steve Luke,
If you haven't done so already,
please check your private messages.
-DOM
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot compile servlet