Monday, August 8, 2011

Solving Package javax.servlet does not exist Error using Eclipse and Ant


Suppose you are working on a web application project with Eclipse IDE, Apache ant and Tomcat server. When you compile and run the program you will get the following error saying that Servlet.jar API cannot be found.

Package  javax.servlet  does not exist

This error will get even if the servlet.jar API is available in the lib directory of the Tomcat web container. The reason for this error is you have not set the CLASSPATH environmental variable for referring javax.servlet API. In addition you have not set the Apache Ant run time class path to javax.servlet API.
You can follow the instructions given below to set both the classpaths properly.

1. Setting up CLASSPATH environmental variable.

 Right Click on My Computer -> Properties -> Advanced tab -> Environment Variables
(In that you can amend/create CLASSPATH environment variable to servlet.jar
(In my case, CLASSPATH=C:/Program Files/Apache Software Foundation/Tomcat 6.0/lib/javax.servlet.jar )

2. Setting up Apache Ant runtime classpath

In addition, it is required to include the javax.servlet API (servlet.jar ) into the Apache Ant runtime. This can be done using your Eclipse IDE as follows.
Click on Window menu -> preferences -> Ant -> Runtime -> Global Entries
(In this location, you can add the servlet.jar API to the Apache Ant runtime as an external JAR file).


if you follow the above instructions properly,  you should be able to compile and deploy your web application without having such compilation error.

5 comments:

  1. Setting up Apache Ant runtime classpath solved the issue. Thanks.

    ReplyDelete
  2. This is a nice post in an interesting line of content.Thanks for sharing this article, great way of bring this topic to discussion.

    Java training in Chennai

    Java training in Bangalore

    ReplyDelete
  3. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Online DevOps Certification Course - Gangboard
    Best Devops Training institute in Chennai

    ReplyDelete

  4. This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb.
    This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here 


    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  5. in linux command prompt how to set the apache ant runtime classpath

    ReplyDelete