Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to set Classpath to run Servlets

 
Maxi Malahleha
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\MyProjects>javac -classpath "/Tomcat/lib/servlet-api.jar:. " BeerSelect.jav
a
BeerSelect.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
BeerSelect.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
BeerSelect.java:6: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet{
^
BeerSelect.java:7: cannot find symbol
symbol : class HttpServletRequest
location: class BeerSelect
public void doPost(HttpServletRequest request,
^
BeerSelect.java:8: cannot find symbol
symbol : class HttpServletResponse
location: class BeerSelect
HttpServletResponse response) throws IOException, ServletExcepti
on{
^
BeerSelect.java:8: cannot find symbol
symbol : class ServletException
location: class BeerSelect
HttpServletResponse response) throws IOException, ServletExcepti
on{
^
6 errors

Please help

this is how I set up my classpath Iam Using (.bat)

set JAVA_HOME=C:\jdk1.5.0_06

PATH=%PATH%;.;C:\jdk1.5.0_06\bin

set CLASSPATH = %CLASSPATH%;.;C:\MyProjects\Tomcat\lib\servlet-api.jar
 
Jan van Mansum
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you are working on Windows, but your are using a Unix-style path in your classpath argument to javac.
 
Maxi Malahleha
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you are working on Windows, but your are using a Unix-style path in your classpath argument to javac.

Hi Jan Please tell me which style to use for WIN
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bodix Malahleha:
C:\MyProjects>javac -classpath "/Tomcat/lib/servlet-api.jar:. " BeerSelect.java

this is how I set up my classpath Iam Using (.bat)
set CLASSPATH = %CLASSPATH%;.;C:\MyProjects\Tomcat\lib\servlet-api.jar


The format of your CLASSPATH variable is correct, but javac is not using it because you specify the -classpath option. Change the format of your -classpath value to the same as your CLASSPATH variable (\ instead of / and ; instead of and it should work.
[ November 26, 2007: Message edited by: Joanne Neal ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bodix,

Two things to keep in mind.
First:
The more you crosspost your question and/or re-ask them in the same forum, the less people will want to help you.
This is the third thread that you've started for the same issue.
You were getting plenty of help in this one:
http://www.coderanch.com/t/408729/java/java/Compler-Errors
Starting a new thread only adds confusion, causes duplication of effort, and annoys the people who who have made suggestions, only to find out that someone else has already suggested the same thing to you in another thread.
If you think your question isn't getting good enough answers, see:
http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch for some tips on improving the quality of your question.


Second:
A servlet is a Java class.
Like most non trivial Java classes, it has some dependencies that you will have to satisfy in order to compile it.
If you're having a hard time getting your servlet to compile because you're unsure about packages, javac, or classpaths, I suggest you step back from servlet programming for a bit and find a book or tutorial on Java.
It's a lot easier to gain an understanding of packages and classpaths when working with small command line applications. If you already have a firm grip on these issues, learning servlets will be a lot easier and enjoyable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic