File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java doesn't know where to find servlet packages

 
J Mangual
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reading the headfirst servlets book and I'm trying to compile the first servlet in chapter 3, but Java is complaining that it can't find the servlet classes. Please help, so that I may continue taking over the world.
- John

C:\Documents and Settings\jm\My Documents\beerV1>javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\l
ib\servlet-api.jar:classes:." -d classes src\com\example\web\BeerSelect.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,
^
src\com\example\web\BeerSelect.java:9: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
HttpServletResponse response)
^
src\com\example\web\BeerSelect.java:10: cannot find symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
throws IOException, ServletException{
^
6 errors
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to tell the compiler so by adding the path to yur servlet api classes to your classpath.
 
Vinod K Singh
Ranch Hand
Posts: 198
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by J Mangual:
C:\Documents and Settings\jm\My Documents\beerV1>javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\l
ib\servlet-api.jar:classes:." -d classes src\com\example\web\BeerSelect.java

Classpath entries should be separated by semi-colon ;
[ November 15, 2008: Message edited by: Vinod K Singh ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vinod K Singh:

Classpath entries should be separated by semi-colon ;


On Microsoft Windows, yes. On other systems, the colon he's used is correct.
 
J Mangual
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Semicolons (;) in Windows, huh... now it compiles.

Follow-up, there are three things I'm specifying in the classpath, servlet-api.jar, "classes" (not sure what that is) and "." which I guess means the current folder.

[edit]Disable smilies. CR[/edit]
[ November 17, 2008: Message edited by: Campbell Ritchie ]
 
Vinod K Singh
Ranch Hand
Posts: 198
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:

On Microsoft Windows, yes. On other systems, the colon he's used is correct.

The directory structure in classpath seems to be from Windows thats why suggested for semi colon.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic