• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiling Servlet  RSS feed

 
Prasanna Adhikari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have written java servlet program. But when I try to compile it, it shows error message similar to servlet package not found. I'm using Dr.Java for compiling and Apache Tomcat server. I have set environment variable (system variable) "CLASSPATH" to D:\>Program_Files\Apache Tomcat\lib\servlet-api.jar
It would be a great help if someone is here.
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your code, command for compilation and error message.
And dont forget to UseCodeTags <- This is the link
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Beginning Java where learning how to compile Java classes and the class path are best discussed.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
Looking forward to helping you.
 
Prasanna Adhikari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I'm trying to do my best for posting.
I was in a hurry to get the answer so I did not read about CodeTags and all.
Hope you'll understand me. And please don't mind if still my post is not perfect. Slowly I'll learn
Here is my code for HelloWorld.java:


And the error message while compiling is like this:
Error: package javax.servlet does not exist
Error: package javax.servlet.http does not exist
Error: cannot find symbol
symbol: class HttpServlet


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code isn't really important. What's important is what you are using to compile the class. Command line?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasanna Adhikari wrote:I have set environment variable (system variable) "CLASSPATH" to D:\>Program_Files\Apache Tomcat\lib\servlet-api.jar

If you have literally set the CLASSPATH environment variable to: D:\>Program_Files\Apache Tomcat\lib\servlet-api.jar
then that is most likely wrong. Or do you really have a directory named >Program_Files (including the > and the underscore) on drive D?

It should most likely be: D:\Program Files\Apache Tomcat\lib\servlet-api.jar

Be sure to check that the name is exactly correct.
 
Prasanna Adhikari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Jesper de Jong, the path is correct.
The folder is Program_Files in D drive.
I have made it.
And I'm using drJava to compile the code.
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
drJava is IDE or what?
If you are a beginner, it recommended that you start learning by writing the program in a text editor and compiling it through command line.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is probably not a good idea to create a folder called Program_Files because of the possibility of confusion. It is also not a good idea to set a system classpath at all. That usually does more harm than good. you should use the -cp option when compiling, and for a simple class like that stop using drJava and do it from the command line. Try
javac -cp "D:\Program_Files\Apache Tomcat\lib\servlet-api.jar;." HelloWord.java
You probabl need quotes round the name of the path otherwise the space will cause confusion. And it shouldn't contain a >
Then move the servlet jar to a location with a better name. Possible Program Files.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!