C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers

114 comments

10,705 users

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

0 votes
26 views
asked Jan 21, 2014 by john Guru (27,140 points)

1 Answer

0 votes
Ensure that you're using at least Eclipse IDE for Java EE developers (with the EE). It contains development tools to create dynamic web projects and easily integrate servletcontainers (which is part of Web Tools Platform, WTP). You also need to ensure that you already have a servletcontainer installed which implements at least the same Servlet API as the servletcontainer in the production environment, for example Apache Tomcat, Oracle Glassfish, JBoss AS, etc.
 
A servletcontainer is a concrete implementation of the Servlet API. Note that the Java EE SDK download at Oracle.com basically contains Glassfish. So if you happen to already have downloaded Java EE SDK, then you already have Glassfish. Also note that for example Glassfish and JBoss AS are more than just a servletcontainer, they also supports JSF, EJB, JPA and all other Java EE fanciness.
 
Once having installed both, do the following steps in Eclipse:
 
Integrate servletcontainer in Eclipse. Open the Servers view in the bottom box, rightclick there and choose New > Server. Pick the appropriate servletcontainer make and version and walk through the wizard.
 
Create new dynamic web project in Eclipse which is associated with the integrated servletcontainer. Open the Project Navigator on the left hand side. Rightclick there and choose New > Project and then in menu Web > Dynamic Web Project and set the Target Runtime to the integrated server. Eclipse will then automatically take the servletcontainer's libraries in the build path. This way you'll be able to import and use the Servlet API.
You should above all never manually copy/download/move/include the individual servletcontainer-specific libraries like servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar, javaee.jar, etc. It would only lead to future portability, compatibility, classpath and maintainability troubles, because your webapp would not work when it's deployed to a servletcontainer of a different make/version than where those libraries are originally obtained from.
 
Here are some typical exceptions which you can get when you litter the /WEB-INF/lib or even /JRE/lib, /JRE/lib/ext, etc with servletcontainer-specific libraries
 
answered Jan 21, 2014 by sara Guru (24,570 points)

Related questions

0 votes
1 answer 113 views
0 votes
1 answer 10 views
10 views asked Jan 3, 2014 by sara Guru (24,570 points)
0 votes
1 answer 248 views
0 votes
1 answer 52 views
0 votes
2 answers 21 views
21 views asked Jan 20, 2014 by john Guru (27,140 points)
...