views:

158

answers:

2

I downloaded Eclipse JEE IDE to build Java Web Applications (servlets and jsp pages). But it still not supporting javax.servlet package.

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

+1  A: 

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.
Kaleb Brasee
I would like to go with adding server profile to my workspace. Could you please tell me how to add the server profile?
Yatendra Goel
Sure, I added instructions for adding the server profile to your workspace, and then adding the server runtime libraries to your project.
Kaleb Brasee
+1  A: 

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).

BalusC