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?
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)
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.
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.
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
For me doesnt put jars to lib directory and set to Build path enought.
The right thing was add it to Deployment Assembly.
Original asnwer
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
精彩评论