I'm using Eclipse 3.6 Helios (for Java Developers) and want to add the javax.servlet package to one of my projects. What do I need to configure/download?
6 Answers
To expound on darioo's answer with a concrete example. Tomcat 7 installed using homebrew on OS X, using Eclipse:
- Right click your project folder, select Properties at the bottom of the context menu.
- Select "Java Build Path"
- Click Libraries" tab
- Click "Add Library..." button on right (about halfway down)
- Select "Server Runtime" click "Next"
- Select your Tomcat version from the list
- Click Finish
What? No Tomcat version is listed even though you have it installed via homebrew??
- Switch to the Java EE perspective (top right)
- In the "Window" menu select "Show View" -> "Servers"
- In the Servers tab (typically at bottom) right click and select "New > Server"
- Add the path to the homebrew tomcat installation in the dialog/wizard (something like: /usr/local/Cellar/tomcat/7.0.14/libexec)

- 20,030
- 7
- 43
- 238

- 2,362
- 23
- 15
-
+1 great answer, but... what? No Java EE perspective is listed? – Shabbyrobe Mar 28 '12 at 01:58
-
4I worked it out - I had only installed the basic eclipse, not the version for Java EE. To add Java EE to your installation in Eclipse 3.7, click "Help" menu -> "Install new software". In the "work with" drop down, select "all available sites". Wait 10 million years for eclipse to do a handful of HTTP requests, then type "Java EE" in the filter box. Check "Eclipse Java EE Developer Tools", click "Finish", accept the licenses, wait another 10 million years for Eclipse to go through another titanic struggle with rudimentary HTTP, restart when prompted, then you're golden. – Shabbyrobe Mar 28 '12 at 02:04
Right click on your project -> properties -> build path. Add to your build path jar
file(s) that have the javax.servlet
implemenation. Ite depends on your servlet container or application server what file(s) you need to include, so search for that information.

- 46,442
- 10
- 75
- 103
When you define a server in server view, then it will create you a server runtime library with server libs (including servlet api), that can be assigned to your project. However, then everybody that uses your project, need to create the same type of runtime in his/her eclipse workspace even for compiling.
If you directly download the servlet api jar, than it could lead to problems, since it will be included into the artifacts of your projects, but will be also present in servlet container.
In Maven it is much nicer, since you can define the servlet api interfaces as a "provided" dependency, that means it is present in the "to be production" environment.

- 9,646
- 2
- 59
- 113
Go to
JBoss\jboss-eap-6.1\modules\system\layers\base\javax\servlet\api\main
include JAR
jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar
For me it worked

- 109
- 1
- 4
For me doesnt put jars to lib directory and set to Build path enought.
The right thing was add it to Deployment Assembly.

- 1
- 1

- 21
- 6
-
Try expanding your answers by giving an excerpt of the link and why you're linking it. – Elias Oct 10 '13 at 20:15
-
For this problem you can if You use InteliJ IDEA editor go to menu File/project Structure and click on item SDKs and chose on right side in tab menu SourcePath. And than click on + in green color , on right . Then You can see window there you can chose path to servlet-api.jar file. At the end before chouse with one click this or other who is needed file click on button OK few time and you have what you need. – Miodrag Trajanovic Oct 20 '20 at 22:17
Download the file from http://www.java2s.com/Code/Jar/STUVWXYZ/Downloadjavaxservletjar.htm
Make a folder ("lib") inside the project folder and move that jar file to there.
In Eclipse, right click on project > BuildPath > Configure BuildPath > Libraries > Add External Jar
Thats all

- 12,029
- 19
- 65
- 84
-
5No! Big chance that your webapp won't be able to run on the targeted servletcontainer! You should include the libraries of the targeted runtime in the buildpath: http://stackoverflow.com/questions/4076601/java-servlets-cant-find-the-object – BalusC Nov 18 '10 at 11:32
-