Javax.servlet package does not exist

When you import the javax.servlet package into a java file, this package is in eclipse. However, when I run the Ant build package, I get the error javax.servlet does not exist. "I assume this is a build path problem, but I'm not sure how to fix it. I updated and cleaned the project, changed the build order and checked that the package is located in the expected .jar file, but the error persists. Any ideas?

+4
source share
2 answers

Inside the eclipse, the compiler uses server-side run-time frames to get these definitions.

In Ant you need to add the appropriate jar files.

For example, you can use servlet-api.jar from the Apache Tomcat lib directory. This does not mean that you can only deploy against tomcat, you should be able to deploy to any application server that implements the same version of the servlet API.

+7
source

It might be worth printing the class path from the compilation target, this will make it easier to determine if there are any problems with the classpath.

You can print class paths inside ant targets using this technique .

+1
source

All Articles