简体   繁体   English

包javax.servlet不存在

[英]package javax.servlet does not exist

When importing the javax.servlet package in the java file, this package is found by eclipse. 在java文件中导入javax.servlet包时,eclipse会找到这个包。 However, when running an Ant build I get the error 'package javax.servlet does not exist'. 但是,在运行Ant构建时,我得到错误'package javax.servlet不存在'。 I'm guessing this is a build path issue but I'm not sure how to fix it. 我猜这是一个构建路径问题,但我不知道如何解决它。 I've refreshed and cleaned the project, changed the order of the build path and verified that the package is in the expected .jar file but the error will not go away. 我刷新并清理了项目,更改了构建路径的顺序,并验证了包是否在预期的.jar文件中,但错误不会消失。 Any ideas? 有任何想法吗?

Inside eclipse, the compile is using the server runtime jars get these definitions. 在eclipse里面,编译是使用服务器运行时jar获取这些定义。

In Ant you need to add the appropriate jar files. 在Ant中,您需要添加适当的jar文件。

For example, you can use the servlet-api.jar from Apache Tomcat's lib directory. 例如,您可以使用Apache Tomcat的lib目录中的servlet-api.jar This doesn't mean you can only deploy against tomcat, you should be able to deploy against any application server which implements the same version of the Servlet API. 这并不意味着您只能针对tomcat进行部署,您应该能够针对实现相同版本的Servlet API的任何应用程序服务器进行部署。

It might be worth printing out the classpath from within the compile target, this would make it easier to determine if there are any classpath problems. 可能值得从编译目标中打印出类路径,这样可以更容易地确定是否存在任何类路径问题。

You can print classpaths inside ant targets using this technique . 您可以使用此技术在ant目标内打印类路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM