Eclipse fails recognize the Java EE packages when refer the Project's Web-inf lib javaee.jar build path but recognizes the ...?

StackOverflow https://stackoverflow.com/questions/15182122

Question

On my development laptop computer, I have installed

*GlassFish Server Open Source Edition 3.1.2.2 (build 5). *Eclipse Java EE IDE for Web Developers.

Version: Helios Release Build id: 20100617-1415

*Server version: 5.6.10-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Using Eclipse Helios, I am building a simple Dynamic Web Project that contains an extended HttpServlet class. It's pretty simple. The GlassFish javaee.jar file came along with the GlassFish Server Open Source Edition 3.1.2.2 installation, and therefore, it is located in the following directory:

C:\glassfish3\glassfish\lib\javaee.jar

Therefore, the following imports are all valid as long as I add the C:\glassfish3\glassfish\lib\javaee.jar from the glassfish lib directory:

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

However, if I take the alternative approach of first copying the C:\glassfish3\glassfish\lib\javaee.jar over to my {BlahBlahProjectFolderNameBlahBlah}\WebContent\WEB-INF\lib, and then adding the {BlahBlahProjectFolderNameBlahBlah}\WebContent\WEB-INF\lib\javaee.jar to the Eclipse Build Path then Eclipse would complain that the following packages are Unrecognized:

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Why does Eclipse fail to recognize typical Java EE Servlet packages when I refer to the {BlahBlahProjectFolderNameBlahBlah}\WebContent\WEB-INF\lib\javaee.jar build path but then recognizes the typical Java EE Servlet packages when I refer to the C:\glassfish3\glassfish\lib\javaee.jar ?

Was it helpful?

Solution

Thank you @arjan-tijms and @balusc for their help. The following link helped me understand:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top