Eclipse Java EE IDE does not support javax.servlet package

I downloaded the Eclipse Java EE IDE to create Java web applications (servlets and JSP pages). But it still does not support the javax.servlet package.

Why? What reason? Is there any plugin I need to install?

+4
source share
2 answers

You need to integrate the servlet container into Eclipse and link it to your Dynamic Web Project. By default, Eclipse does not come with a servlet container. You need to download and install it separately. Widely used is Apache Tomcat . Just download the zip and extract it somewhere.

Then in Eclipse, go to the Servers view in the box on the right. Then add a new server where you select Apache Tomcat 6 from the list and specify the root folder of Tomcat (where you extracted it). You can then select it from the Target Runtime drop-down list during the creation of the Dynamic Web Project Creation Wizard. Or if you have already created one, but havenโ€™t connected it to the server, then change it in the "Target deadlines" section of the project properties. Thus, server libraries will be automatically added to the project creation path. This, finally, is 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 little differently than described above, but that's also enough), and here's a text / screenshot (you can just skip part of the JSF if thatโ€™s not interesting yet).

+11
source

You probably need to create a dynamic web project instead of a regular Java project.

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

  • To add a server profile, go to Window -> Preferences -> Server -> Runtime Environments . Click Add... , select the type of server you are using, specify the directory in which this server is installed, and click Finish .
  • Now that you have added the server, you should add it to the project as a library. Right-click the project, then go to Properties -> Java Build Path -> Libraries -> Add Library -> Server Runtime , select the server you just added from the list, and click Finish . This will make all server libraries available for your project.
+6
source

Source: https://habr.com/ru/post/1300576/


All Articles