无法解析 Java 类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/729960/
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
Java type cannot be resolved
提问by smauel
I have a statement
我有一个声明
String pass = com.liferay.portal.util.PortalUtil.getUserPassword(renderRequest);
that causes the following error in eclipse IDE:
这会导致 Eclipse IDE 中出现以下错误:
The type javax.servlet.http.HttpSession cannot be resolved. It is indirectly referenced from required .class files
无法解析 javax.servlet.http.HttpSession 类型。它是从所需的 .class 文件间接引用的
Why is this error occuring? I have added an import statement for the type but yet the error remains. How can I remove this error?
为什么会出现这个错误?我为该类型添加了一个导入语句,但错误仍然存在。我怎样才能消除这个错误?
Thanks for your help.
谢谢你的帮助。
采纳答案by Jon Skeet
It sounds like you haven't referenced the right libraries. Add a reference to servlet.jar.
听起来您没有引用正确的库。添加对 servlet.jar 的引用。
回答by Michael Borgwardt
You need to put the definition of that class (usually contained in a servlet.jar file) into the build path of your project (right-click on the project, select "Properties" and then "Build Path").
您需要将该类的定义(通常包含在 servlet.jar 文件中)放入项目的构建路径中(右键单击项目,选择“属性”,然后选择“构建路径”)。
回答by Vincent De Baere
Check your project setup. If I recall correctly, this has to do with com.liferay.portal.util.PortalUtil.getUserPassword(renderRequest) using javax.servlet.http.HttpSession under the hood, but eclipse isn't able to find that class. Try adding the servlet api jar to the project class path
检查您的项目设置。如果我没记错的话,这与 com.liferay.portal.util.PortalUtil.getUserPassword(renderRequest) 使用 javax.servlet.http.HttpSession 在引擎盖下有关,但 eclipse 无法找到该类。尝试将 servlet api jar 添加到项目类路径
回答by karthik339
Download Apache-Tomcat. Browse to the lib folder. Now open eclipse and go to build-path-> configure build path-> add external libraries.
下载 Apache-Tomcat。浏览到 lib 文件夹。现在打开 eclipse 并转到 build-path-> configure build path-> add external libraries。
回答by Gaurav Varshney
In order to remove this error You need to add the Servlet API to your classpath. In Tomcat 6.0, this is in a JAR called servlet-api.jar in Tomcat's lib folder. You can either add a reference to that JAR to the project's classpath, or put a copy of the JAR in your Eclipse project and add it to the classpath from there.
为了消除此错误,您需要将 Servlet API 添加到您的类路径中。在 Tomcat 6.0 中,它位于 Tomcat 的 lib 文件夹中名为 servlet-api.jar 的 JAR 中。您可以将对该 JAR 的引用添加到项目的类路径中,也可以将 JAR 的副本放入 Eclipse 项目中,然后从那里将其添加到类路径中。
If you want to leave the JAR in Tomcat's lib folder:
如果要将 JAR 留在 Tomcat 的 lib 文件夹中:
Right-click the project, click Properties. Choose Java Build Path. Click Add External JARs... Browse to find servlet-api.jar and select it. Click OK to update the build path.
右键单击项目,单击属性。选择 Java 构建路径。单击 Add External JARs... 浏览以找到 servlet-api.jar 并选择它。单击“确定”以更新构建路径。
if you copy the JAR into your project:
如果您将 JAR 复制到您的项目中:
Right-click the project, click Properties. Choose Java Build Path. Click Add JARs... Find servlet-api.jar in your project and select it. Click OK to update the build path.
右键单击项目,单击属性。选择 Java 构建路径。单击 Add JARs... 在您的项目中找到 servlet-api.jar 并选择它。单击“确定”以更新构建路径。