How to get Eclipse to recognize Java EE jar files so that servlets can compile?

I am configuring the Eclipse version for Java EE to compile Servlets. I have a problem when Eclipse says that "HttpServlet" cannot be resolved because it cannot find Java EE jar files.

I am using Windows XP. I already have Tomcat 6.0. I think the easiest solution would be to link the servlet-api.jar file with the Tomcat installation.

I added it to the Windows CLASSPATH environment variable. Now it looks like this:.: C: \ Program Files \ Java \ jre1.6.0_04 \ lib \ ext \ QTJava.zip; C: \ Program Files \ Apache Software Foundation \ Tomcat 6.0 \ lib \ servlet-api.jar

This did not work. Am I doing something wrong?

What is the best solution?

+5
source share
5 answers

You can add the servlet-api.jar file to the project properties. In the project hierarchy, right-click on the project name-> properties-> Java build path-> Libraries. From there, add servlet-api.jar as an external jar file.

+7
source

First add Tomcat Server by going to New -> Server -> Server. Then right-click on your project, select "Build Path" → "Configure Build Path". Click Add Library → Server Runtime and select Add Tomcat Server.

+6
source

, :

" -" ( New- > Project...- > Web- > Dynamic Web Project)?

- Librairies, :

  • - Librairies
  • JRE
  • Apache Tomcat vx.y

"Window → Preferences... → Server → Installed Runtimes"?

TOMCAT_HOME Prefereces → Java → Build Path → Classpath, tomcat? .

+2

Eclipse CLASSPATH ( , , ). , , . Java Build Path.

+1

java :

  • eclipse 'lib'.
  • lib.
  • Right-click the servlet file file in the Navigator view and select Add to Create Path.

For more complex projects, I would suggest Maven + m2eclipse.

+1
source

All Articles