Project compiles fine in Eclipse but not with ant file


I am making a simple java-based web application using Eclipse and Tomcat.  The Eclipse project compiles without any problem in Eclipse, using the compilation capability provided within Eclipse.  But, when I try to compile use an Ant build file (build.xml) within the Eclipse project, it tells me that it cannot find the servlet package when Eclipse was able to.  This package is definitely recognised by Eclipse because when I remove the jar file from Eclipse, the Eclipse compiler complains.  I am very stuck on this, help would be much appreciated.  Here is the compile error from the Ant build:


Buildfile: C:\TenantLife\workspace\RABProj\build.xml
init:
compile:
    [javac] Compiling 8 source files to C:\apache-tomcat-5.5.16\webapps\bikestore\war\WEB-INF\classes
    [javac] C:\apache-tomcat-5.5.16\webapps\bikestore\src\com\springbook\BikesController.java:6: package javax.servlet.http does not exist
    [javac] import javax.servlet.http.HttpServletResponse;
    [javac] ^
    [javac] C:\apache-tomcat-5.5.16\webapps\bikestore\src\com\springbook\BikesController.java:7: package javax.servlet.http does not exist
    [javac] import javax.servlet.http.HttpServletRequest;
    [javac] ^
    [javac] C:\apache-tomcat-5.5.16\webapps\bikestore\src\com\springbook\BikesController.java:21: cannot resolve symbol
    [javac] symbol  : class HttpServletRequest
    [javac] location: class com.springbook.BikesController
    [javac] public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
    [javac] ^
    [javac] C:\apache-tomcat-5.5.16\webapps\bikestore\src\com\springbook\BikesController.java:21: cannot resolve symbol
    [javac] symbol  : class HttpServletResponse
    [javac] location: class com.springbook.BikesController
    [javac] public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
    [javac] ^
    [javac] C:\apache-tomcat-5.5.16\webapps\bikestore\src\com\springbook\EditBikeController.java:20: cannot resolve symbol
    [javac] symbol  : class HttpServletRequest
    [javac] location: class com.springbook.EditBikeController
    [javac] public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    [javac] ^
    [javac] C:\apache-tomcat-5.5.16\webapps\bikestore\src\com\springbook\EditBikeController.java:20: cannot resolve symbol
    [javac] symbol  : class HttpServletResponse
    [javac] location: class com.springbook.EditBikeController
    [javac] public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    [javac] ^
    [javac] C:\apache-tomcat-5.5.16\webapps\bikestore\src\com\springbook\SubmitBikeController.java:21: cannot resolve symbol
    [javac] symbol  : class HttpServletRequest
    [javac] location: class com.springbook.SubmitBikeController
    [javac] public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
    [javac] ^
    [javac] C:\apache-tomcat-5.5.16\webapps\bikestore\src\com\springbook\SubmitBikeController.java:21: cannot resolve symbol
    [javac] symbol  : class HttpServletResponse
    [javac] location: class com.springbook.SubmitBikeController
    [javac] public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
    [javac] ^
    [javac] 8 errors

BUILD FAILED
C:\TenantLife\workspace\RABProj\build.xml:41: Compile failed; see the compiler error output for details.

Total time: 2 seconds


tlDeveloperAsked:
Who is Participating?
 
objectsCommented:
add servlet.jar to <ant>/lib

where <ant> is where you have ant installed
0
 
CEHJCommented:
Make sure servlet.jar is in the *Ant* build path (classpath)
0
 
tlDeveloperAuthor Commented:

It turned out there was typo in the build.xml file where someone wrote servlet.jar instead of servlet-api.jar (which was the correct file name).  The eclipse project was using a different jar file altogether and compiled for that reason.  I appreciate all the advice, it really helped me get unstuck (I was looking in all the wrong places for something to be wrong).

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
CEHJCommented:
tlDeveloper, why in that case did you accept that answer, which in any case wasn't right?
0
 
tlDeveloperAuthor Commented:

Both sets of comments were helpful in pointing me in the right direction of finding the problem.  I would have liked to accept answers for both people to give both credit but the site does not allow it, sorry.  Thank you for the help though.

0
 
CEHJCommented:
>>but the site does not allow it, sorry.

It does in fact, and can be corrected now as well.
0
 
tlDeveloperAuthor Commented:

I'd be happy to accept your answer as well, how do I do that?  Thanks again for the help.

0
 
CEHJCommented:
You don't need to do anything yet. A page editor will post in this Q. soon
0
 
Mayank SAssociate Director - Product EngineeringCommented:
objects, CEHJ - are you subscribed to Venabili's PE notifier 6 or not?

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21765176.html
0
 
CEHJCommented:
I am
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.