Eclipse Java更新后无法解析导入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2122545/
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
Eclipse the import cannot be resolved after Java update
提问by newbie
I have class that uses hibernate, I have included all required jars to classpath and class worked before Java updated itself. But now eclipse shows that it cannot resolve some hibernate imports. What could be solution to this?
我有使用 hibernate 的类,我已将所有必需的 jars 包含到类路径中,并且在 Java 更新自身之前工作的类。但是现在 eclipse 显示它无法解析某些休眠导入。有什么办法可以解决这个问题?
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
采纳答案by Omar Al Kababji
If you type (Ctrl + shift + t), or open the Type Explorer and type SessionFactory or Configuration does Eclipse find them? If not, then for sure you have some problems in the .jar files. Try to delete and replace them.
如果您键入 (Ctrl + shift + t),或打开类型资源管理器并键入 SessionFactory 或 Configuration,Eclipse 会找到它们吗?如果没有,那么您肯定在 .jar 文件中有一些问题。尝试删除并替换它们。
By the way are you using a Mac or PC?
顺便说一下,您使用的是 Mac 还是 PC?
回答by sfussenegger
Did you try "Project > Clean ..."? What is the exact error message? After a Java update, you might need to update the path to the JDK: "Window > Preferences > Java > Installed JREs"
您是否尝试过“项目>清理...”?确切的错误消息是什么?在 Java 更新后,您可能需要更新 JDK 的路径:“Window > Preferences > Java > Installed JREs”
回答by Gene Golovchinsky
I experienced a similar problem that got fixed when I used Grails Tools > Refresh Dependencies (Alt+G,R). This was in SpringSource Tool Suite 2.7.1.
当我使用 Grails Tools > Refresh Dependencies (Alt+G,R) 时,我遇到了类似的问题。这是在 SpringSource Tool Suite 2.7.1 中。
I had to run that once to get the plugins to initialize correctly (after an import from SVN) and then a second time to get references to work.
我必须运行一次才能使插件正确初始化(从 SVN 导入后),然后第二次运行以获取工作引用。
回答by Dharmesh Patel
even i was facing the same problem . every thing was working fine but all of a suden every jsp page started giving me error saying org.apache.jasper.JasperException: Unable to compile class for JSP:
甚至我也面临同样的问题。一切正常,但突然每个jsp页面都开始给我错误,说org.apache.jasper.JasperException:无法为JSP编译类:
An error occurred at line: 1 in the generated java file The type org.hibernate.SessionFactory cannot be resolved. It is indirectly referenced from required .class files
An error occurred at line: 9 in the generated java file Only a type can be imported. org.hibernate.Query resolves to a package
An error occurred at line: 11 in the generated java file Only a type can be imported. org.hibernate.Session resolves to a package
An error occurred at line: 12 in the generated java file Only a type can be imported. org.hibernate.SessionFactory resolves to a package
An error occurred at line: 13 in the generated java file Only a type can be imported. org.hibernate.cfg.Configuration resolves to a package
生成的 java 文件中的第 1 行发生错误无法解析类型 org.hibernate.SessionFactory。它是从所需的 .class 文件间接引用的
生成的 java 文件中第 9 行发生错误 只能导入一个类型。org.hibernate.Query 解析为一个包
生成的 java 文件中第 11 行发生错误 只能导入一个类型。org.hibernate.Session 解析为一个包
生成的 java 文件中第 12 行发生错误 只能导入一个类型。org.hibernate.SessionFactory 解析为一个包
生成的 java 文件中第 13 行发生错误 只能导入一个类型。org.hibernate.cfg.Configuration 解析为一个包
to solve thi problem in eclipse i removed/deleted the server from eclipse and added my tomcat server back and every thing started working same as before .....
为了解决 eclipse 中的这个问题,我从 eclipse 中删除/删除了服务器并重新添加了我的 tomcat 服务器,一切都开始像以前一样工作......
Thanks
谢谢
回答by Duc Dat Nguyen
Delete .m2/repository/org/hibernate/*, then in eclipse: Maven/update Project. It will download the dependencies again. It worked for me!
删除.m2/repository/org/hibernate/*,然后在eclipse中:Maven/update Project。它将再次下载依赖项。它对我有用!
回答by Osip Akopiants
I faced this problem today.I think eclipse tell me that he want to resolve something but don't know what problem and how.And here it is:
我今天遇到了这个问题。我认为 eclipse 告诉我他想解决某些问题,但不知道是什么问题以及如何解决。这里是:
SessionFactory factory;
try {
factory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
Maby it helps.In my case it was exception handling.
Maby 它有帮助。就我而言,它是异常处理。