954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Is "javax.servlet" included in Eclipse SDK

I'm trying to learn Java Servlets on my own but I'm having some very basic problems.

The code

"import javax.servlet.ServletException;"


produces a compiler error, "the import javax.servlet cannot be resolved".

I'm using version 3.2.2. Why am I having this problem?

knight fyre
Junior Poster in Training
88 posts since Feb 2008
Reputation Points: 11
Solved Threads: 1
 

Nope by default the Java Plugin for Eclipse only includes Core Java, Servlets are not a part of that.
A short cut to resolve that error would be, in case you have tomcat / some other java enabled server installed, just check in their "lib" folder if you find any jar called "servlet.jar" or "j2ee.jar" or something similar in name and add it to your project's build path in Eclipse, this should solve the compile error.

However you will not be able to test your servlets directly via Eclipse in this case

stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
 

I'm using Tomcat 5.0.

There are multiple lib folders and none of the jar files match exactly. Which folder should I look into? Even if I choose the right folder how exactly should I add it the built path? I attached the search result of "lib".

What is the other method of installing the servlet package?

Attachments searcheresults.JPG 147.96KB
knight fyre
Junior Poster in Training
88 posts since Feb 2008
Reputation Points: 11
Solved Threads: 1
 

if you are using the latest version of tomcat 6.0+ there is a "lib" folder in the ROOT directory of tomcat, you should find the servlet.jar file there.
In tomcat 5.0 I assume it should be in $CATALINA_HOME/share/lib
The second way is to install the J2EE Standard Tools plugin for eclipse.

stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
 

I found the jar file with the packages. Problem solved.

knight fyre
Junior Poster in Training
88 posts since Feb 2008
Reputation Points: 11
Solved Threads: 1
 

javax.servlet.* package is not included in Eclipse. It is present in Tomcat 6.0/lib folder as servlet-api.jar and jsp-api.jar.
These two files can be imported to Eclipse by right clicking on your project's name in the Eclipse's Explorer window and selecting properties option from the popup menu. Then select Libraries tab from Java Build Path and then click Add External Jar option. Browse to the Tomcat installation folder and then select lib folder. Choose file servlet-api.jar and click finish.

varun.x.anand
Newbie Poster
1 post since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You