Reputation:
I am setting up my Java EE version of Eclipse to compile Servlets. I have the problem where Eclipse says "HttpServlet" cannot be resolved because it can't find the Java EE jar files.
I am using Windows XP. I already have Tomcat 6.0 up and running. I think the easiest solution would be to link to the servlet-api.jar file in 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
That didn't work. Am I doing something wrong?
What is the best solution?
Upvotes: 5
Views: 34973
Reputation: 271
First add Tomcat Server by going to New -> Server -> Server. Then right-click on your project, click on Build Path -> Configure Build Path. Click on Add Library -> Server Runtime and Choose the Tomcat Server you added.
Upvotes: 6
Reputation: 98300
For a regular java project you can do:
For more complex projects I would suggest Maven+m2eclipse.
Upvotes: 1
Reputation: 20033
Eclipse doesn't make use of the CLASSPATH environmental variable, or any other (except maybe to find a VM to run). Doing so would make it difficult if not impossible to cleanly target different VMs and servers from the same machine and installation. The list of jars used is solely based on the project's Java Build Path.
Upvotes: 1
Reputation: 4564
You can add the servlet-api.jar file into the project properties. From the project hierarchy right click the project name->properties->Java build path->Libraries tab. From there, add the servlet-api.jar as an external jar file.
Upvotes: 7
Reputation: 1329512
a few thing to check:
Did you create your project as a "Dynamic Web Project" (via New->Project...->Web->Dynamic Web Project) ?
you should have a Web App Librairies directory which does contains:
Did you select a server in "Window -> Preferences... -> Server -> Installed Runtimes" ?
Do you have a TOMCAT_HOME in Prefereces -> Java -> Build Path -> Classpath variable referring to the home directory of your tomcat installation ? Try to add it to your project classpath.
Upvotes: 2