• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to compile servlets  RSS feed

 
Sridhar Venkataraman
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I've just got started with Head First Servlets and JSP.

In chapter 2 [Hands-on MVC], I've tried compiling version 1 of the BeerSelect servlet (the instructions of which are on page 81 of the Indian Subcontinent edition of the book), but the compiler says that the packages imported (javax.servlet and javax.servlet.http) do not exist.

My Development environment is in the folder : c:\MyMVCProjects
My Deployment environment is in the folder : c:\Tomcat\webapps\Beer-v1

I am running the latest versions of both the JRE (1.5.0_06) and Tomcat (5.5.17).

I'm able to compile core Java files (all the programs in Head First Java compiled without any problems )

A screenshot of the commands I typed and the errors is present HERE.

What is wrong here? Or Am I doing something wrong? I've tried compiling on my desktop and laptop (both of them run the same JDK and Tomcat versions), but I get the same error.

Thanks in advance for the help.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem with your environmental variables. Check TOMCAT_HOME, JAVA_HOME and CLASSPATH again.
 
Sridhar Venkataraman
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have any of those Environment variables set up...I've only added the bin directory of the JRE in my PATH variable.

Can anyone please tell me how best to set up the variables so that I can compile Java/Servlet related files with ease?

Thanks very much.
 
abhijit Ohal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just add sevlet-api.jar or rt.jar in your classpath & compile it
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should be no need to include rt.jar, servlet-api.jar is sufficient. It looks like the the classpath includes colons - on Windows you need to use semicolons; colons are used on Unix-ish operating systems.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this entry in our servlets faq section.

It lists the dependencies that need to be listed in your classpath.
It also has links to the excellent FAQ entries on classpaths.

Moving to Java in General (Beginner) where classpath issues are discussed.
 
Sridhar Venkataraman
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all. I'm now fairly clear on the CLASSPATH variable, but what do the TOMCAT_HOME and JAVA_HOME variables do? How do I set them up, if necessary?

Also, do I need to set my CLASSPATH before compiling every project of mine using the command prompt in Windows? Is it possible to have a setting such that I don't need to specify the CLASSPATH to the system every single time, or atleast something which makes it convenient to compile files from anywhere in the system with ease?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!