Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat installed successfully. Unable to compile example code.

 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I downloaded latest Tomcat and installed on Windows XP couple of days back. It is working fine. However, when I created an example code and tried to compile it, I am seeing the error messages package javax.servlet doesn't exist etc. I added the servlet-api.jar to CLASSPATH but I still have compilation problem. Any idea what's wrong?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15633
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Please show us exactly what you did: what is your classpath set to, what are you typing in to compile your source code, copy and paste the exact error message that you get from the compiler. That will make it easier to help you find where exactly the problem is.
 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
CLASSPATH is .;D:\Backup_old\michael\exercises;"D:\Backup_old\michael\Tomcat 6.0\lib\servlet-api.jar";"D:\Backup_old\michael\Tomcat 6.0\lib\jsp-api.jar"
I tried to compile WelcomeServlet.java located in D:\Backup_old\michael\exercises. This is the directory where all my Java classes are compiled. Error messages are
package javax.servlet does not exist
package javax.servlet.http does not exist
cannot find symbol HttpServlet
cannot find symbol HttpServletRequest
cannot find symbol HttpServletResponse
cannot find symbol ServletException

Code is given below:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet {
protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { //process get requests from clients
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<?xml version = \"1.0\"?>");
out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
out.println( "<html xmlns = \"http://www.w3.org/1999/xhtml\">" );

out.println( "<head>" );
out.println( "<title>A Simple Servlet Example</title>" );
out.println( "</head>" );

out.println( "<body>" );
out.println( "<h1>Welcome to Servlets!</h1>" );
out.println( "</body>" );

out.println( "</html>" );
out.close();
}
}
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check if servlet-api.jar exists at the location D:\Backup_old\michael\Tomcat 6.0\lib\. I think the path should be D:\Backup_old\michael\Tomcat 6.0\common\lib\.

Hope this helps
 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no common directory. I first searched the computer for servlet.jar. I couldn't find but I found servlet-api.jar etc. After setting classpath I tried compilation with javac WelcomeServlet.java and got the above error messages
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just try
javac -classpath "D:\Backup_old\michael\Tomcat 6.0\lib\servlet-api.jar" WelcomeServlet.java
 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's excellent. It worked. I am still puzzled why environmental variable didn't work.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by michael tall:
That's excellent. It worked. I am still puzzled why environmental variable didn't work.


Great!! I knew it would .

Now lets take a look at the environment variable,

.;D:\Backup_old\michael\exercises;"D:\Backup_old\michael\Tomcat 6.0\lib\servlet-api.jar";"D:\Backup_old\michael\Tomcat 6.0\lib\jsp-api.jar"


now the ".; " dont look good in the beginning, also the double quotes should be in the very beginning and then only at the end(that too because the path contains spaces). Try resetting the classpath.
Lets see if this is the concern.

Hope this helps
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing I forgot to point out earlier, please make use of code tags
while posting code, unformatted code is hard to read and decipher so results in less response .
 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again you're correct. Thanks for the corrections.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by michael tall:
Again you're correct. Thanks for the corrections.


You are welcome , so the problem is fixed, isn't it.
 
michael tall
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Thanks.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by michael tall:
Yes. Thanks.


Good. You are welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic