This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Compler Errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compler Errors " Watch "Compler Errors " New topic
Author

Compler Errors

Maxi Malahleha
Greenhorn

Joined: Dec 11, 2006
Posts: 28
C:\MyProjects>javac -classpath /lib/servlet-api.jar:. BeerSelect.java
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

hi! these are errors I get when trying to compile please help.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How are you setting up your CLASSPATH?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Bodix,
Try:
javac -classpath "/lib/servlet-api.jar:." BeerSelect.java

Also is the lib directory in the root of the file system (what that command says) or in your current directory (would be without the slash)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Maxi Malahleha
Greenhorn

Joined: Dec 11, 2006
Posts: 28
Jeanne
my lib is in my current directory
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Bodix,
It will be a lot easier for us to help you if you answer the questions asked of you.

How are you passing the compiler (javac) your classpath?
If you're not sure what this means then, please describe exactly how you are trying to compile your class.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

The Servlet API classes are not part of Java SE, so you need to add them to the CLASSPATH when you compile your source code.

See: JavaRanch FAQ: Compiling Servlets


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
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
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're setting the classpath up as an environment variable, there is no need to pass it to javac as a command line switch and visa versa.

If you are going to pass it as a command line switch, make sure it's right.
The error message you've posted tells me that it isn't.
Specifically, servlet-api.jar is not being found.
Maxi Malahleha
Greenhorn

Joined: Dec 11, 2006
Posts: 28
"If you are going to pass it as a command line switch, make sure it's right"

hi Ben

I think it is right.

my command line
C:\MyProjects>javac -classpath "/Tomcat/lib/servlet-api.jar:. " BeerSelect.java


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

set CLASSPATH = %CLASSPATH%;.;C:\MyProjects\Tomcat\lib\servlet-api.jar
Maxi Malahleha
Greenhorn

Joined: Dec 11, 2006
Posts: 28
"If you are going to pass it as a command line switch, make sure it's right"

hi Ben

I think it is right.
please help

my command line
C:\MyProjects>javac -classpath "/Tomcat/lib/servlet-api.jar:. " BeerSelect.java


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

set CLASSPATH = %CLASSPATH%;.;C:\MyProjects\Tomcat\lib\servlet-api.jar
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

If you specify the classpath using -classpath, it will ignore the CLASSPATH environment variable. Therefore, it will take only what is specified after that flag.

I think your mistake is in the leading / in the classpath. /Tomcat/lib/servlet-api.jar resolves to C:/Tomcat/lib/servlet-api.jar.

Well it would, but you're using / instead of \. Windows does not recognize /.

Make it "-classpath Tomcat\lib\servlet-api.jar" and it would work. You don't need quotes inside; those are only necessary for each separate path element that contains spaces or other characters the command prompt will otherwise handle differently.

E.g. javac -classpath "C:\Program Files\Java\something.jar";.;%CLASSPATH%


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Maxi Malahleha
Greenhorn

Joined: Dec 11, 2006
Posts: 28
Hi Rob

I still got the same error after the changes
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Where, exactly is servlet-api.jar on your machine?
Cut and paste the full path to the jar file.

Then, tell us exactly what directory you're in when you try to compile your class.

If you're not sure how to copy and paste these from a dos window, see:
http://faq.javaranch.com/java/HowToCopyEnvironmentVariablesAndDirectoryStructures
Maxi Malahleha
Greenhorn

Joined: Dec 11, 2006
Posts: 28
Hi Ben

Where, exactly is servlet-api.jar on your machine?
Cut and paste the full path to the jar file.

Then, tell us exactly what directory you're in when you try to compile your class.

RE: C:\Myprojects\Tomcat\lib\

I am in C:\MyProjects> when I compile my class
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compler Errors
 
Similar Threads
How to Deploy servlet using Tomcat 5
Javac cannot find servlet package
Servlet error
Java doesn't know where to find servlet packages
how to set Classpath to run Servlets