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

how to set Classpath to run Servlets

Maxi Malahleha
Greenhorn

Joined: Dec 11, 2006
Posts: 28
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

Joined: Oct 19, 2007
Posts: 74
Looks like you are working on Windows, but your are using a Unix-style path in your classpath argument to javac.


SCJP 1.4, SCWCD 1.4
Maxi Malahleha
Greenhorn

Joined: Dec 11, 2006
Posts: 28
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

Joined: Aug 05, 2005
Posts: 3528
    
  15
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 ]

Joanne
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to set Classpath to run Servlets