Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compler Errors

 
Maxi Malahleha
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you setting up your CLASSPATH?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Maxi Malahleha
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne
my lib is in my current directory
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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%
 
Maxi Malahleha
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob

I still got the same error after the changes
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic