Link to home
Start Free TrialLog in
Avatar of tlDeveloper
tlDeveloper

asked on

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


SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tlDeveloper
tlDeveloper

ASKER


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).

tlDeveloper, why in that case did you accept that answer, which in any case wasn't right?

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.

>>but the site does not allow it, sorry.

It does in fact, and can be corrected now as well.

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

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

https://www.experts-exchange.com/questions/21765176/Java-PE-notifier-6-experts-please-subscribe.html
I am
:-)