eclipse 包 javax.servlet 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4066728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:15:26  来源:igfitidea点击:

package javax.servlet does not exist

javaeclipse

提问by coder

When importing the javax.servlet package in the java file, this package is found by eclipse. However, when running an Ant build I get the error 'package javax.servlet does not exist'. 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. Any ideas?

在java文件中导入javax.servlet包时,eclipse发现了这个包。但是,在运行 Ant 构建时,我收到错误“包 javax.servlet 不存在”。我猜这是一个构建路径问题,但我不确定如何解决它。我刷新并清理了项目,更改了构建路径的顺序并验证了该包在预期的 .jar 文件中,但错误不会消失。有任何想法吗?

回答by Dunderklumpen

Inside eclipse, the compile is using the server runtime jars get these definitions.

在 eclipse 中,编译是使用服务器运行时 jars 来获取这些定义的。

In Ant you need to add the appropriate jar files.

在 Ant 中,您需要添加适当的 jar 文件。

For example, you can use the servlet-api.jarfrom Apache Tomcat's lib directory. 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.

例如,您可以使用Apache Tomcat 的 lib 目录中的servlet-api.jar。这并不意味着您只能针对 tomcat 进行部署,您应该能够针对实现相同版本的 Servlet API 的任何应用程序服务器进行部署。

回答by jwaddell

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 目标内打印类路径。