• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 488
  • Last Modified:

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


0
tlDeveloper
Asked:
tlDeveloper
2 Solutions
 
CEHJCommented:
Make sure servlet.jar is in the *Ant* build path (classpath)
0
 
objectsCommented:
add servlet.jar to <ant>/lib

where <ant> is where you have ant installed
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now