Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Java EE IDE not supporting javax.servlet package

I downloaded Eclipse Java EE IDE to build Java Web Applications (servlets and JSP pages). But it still is not supporting the javax.servlet package.

Why? What's the reason? Is there any plugin that I need to install?

like image 994
Yatendra Avatar asked Dec 03 '22 06:12

Yatendra


2 Answers

You need to integrate a servlet container in Eclipse and associate it with your Dynamic Web Project. Eclipse doesn't ship with a servlet container by default. You need to download and install it separately. A widely used one is Apache Tomcat. Just download the ZIP and extract it somewhere.

Then in Eclipse, go to the Servers view in the box at the right bottom. Then Add a new server where in you choose Apache Tomcat 6 from the list and point the Tomcat root folder (there where you extracted it). Then you can select it from the Target Runtime dropdown during the Dynamic Web Project creation wizard. Or if you already have created one but didn't associate it with a server, then modify it in the Targeted Runtimes section of the project's properties. This way the server's libraries will be automagically added to the project's buildpath. That's finally also the whole point. The server is basically a concrete implementation of the abstract Servlet API. It has all the API libraries in its /lib folder.

Here's a video tutorial (which does it a bit differently than above described, but it's also sufficient) and here's a text/screenshot tutorial (you can just skip the JSF part if that's not of interest yet).

like image 189
BalusC Avatar answered Dec 28 '22 22:12

BalusC


You probably need to create a Dynamic Web Project instead of a normal Java project.

Or you can add a server profile to your workspace, and then add the server runtime to a Java project's libraries.

  1. To add the server profile, go to Window -> Preferences -> Server -> Runtime Environments. Click Add..., choose the server type that you're using, specify the directory where that server is installed, and click Finish.
  2. Now that you've added the server, you should be able to add it to the project as a library. Right click the project, then go to Properties -> Java Build Path -> Libraries -> Add Library -> Server Runtime, choose the server you just added from the list, and click Finish. This will make all the server's libraries available to your project.
like image 42
Kaleb Brasee Avatar answered Dec 28 '22 22:12

Kaleb Brasee