Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: How do I add the javax.servlet package to a project? [duplicate]

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?

like image 630
Tony the Pony Avatar asked Nov 18 '10 10:11

Tony the Pony


People also ask

How do I import the javax servlet API in my Eclipse project?

Quick Fix- This worked in Eclipse - Right Click on project -> Properties -> Java Build Path (Tab) -> Add External JARs -> locate the servlet api jar implementation (if Tomcat - its named servlet-api. jar) -> click OK. That's it !!

What is javax servlet Httpservlet?

An abstract class that simplifies writing HTTP servlets. It extends the GenericServlet base class and provides an framework for handling the HTTP protocol. Because it is an abstract class, servlet writers must subclass it and override at least one method.

How do I import the javax servlet API in my Netbeans project?

Right-click your project, click on properties->Java Build path->Libraries tab->click Add External JARs->Browse for servlet-api. jar and select it->click OK to update the build path. Right-click the project, click properties->Java Build Path->click ADD JARs->find servlet-api.


3 Answers

To expound on darioo's answer with a concrete example. Tomcat 7 installed using homebrew on OS X, using Eclipse:

  1. Right click your project folder, select Properties at the bottom of the context menu.
  2. Select "Java Build Path"
  3. Click Libraries" tab
  4. Click "Add Library..." button on right (about halfway down)
  5. Select "Server Runtime" click "Next"
  6. Select your Tomcat version from the list
  7. Click Finish

What? No Tomcat version is listed even though you have it installed via homebrew??

  1. Switch to the Java EE perspective (top right)
  2. In the "Window" menu select "Show View" -> "Servers"
  3. In the Servers tab (typically at bottom) right click and select "New > Server"
  4. Add the path to the homebrew tomcat installation in the dialog/wizard (something like: /usr/local/Cellar/tomcat/7.0.14/libexec)

Hope that helps someone who is just getting started out a little.

like image 111
Michael Reed Avatar answered Oct 16 '22 19:10

Michael Reed


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.

like image 24
darioo Avatar answered Oct 16 '22 19:10

darioo


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.

like image 1
Gábor Lipták Avatar answered Oct 16 '22 19:10

Gábor Lipták