eclipse 删除Server Runtime Environment后无法解析import javax.persistence
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37030794/
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
The import javax.persistence cannot be resolved after deleting Server Runtime Environment
提问by majd hwas
I had a working java project, I decided to remove all the Server Runtime Environments in my eclipse. since i am getting many errors like :
我有一个正在运行的 Java 项目,我决定删除 Eclipse 中的所有服务器运行时环境。因为我收到了很多错误,例如:
The import javax.persistence cannot be resolved
,
,
Entity cannot be resolved to a type
... can I restore the state of my project ?
...我可以恢复我的项目状态吗?
After thinking in logical reason , I think that the prbolem issued after that I had edited the PATH Variable in windows , can someone tell me what I shouldhave in this PATH variable to get the package javax.persistence working ?
在逻辑上思考之后,我认为在我在 Windows 中编辑了 PATH 变量之后发出的 prbolem,有人能告诉我在这个 PATH 变量中我应该有什么来使包 javax.persistence 工作吗?
回答by Brod
To resolve: "The import javax.persistence cannot be resolved" you need to add the jar containing javax.persistence.Entity to your path. It is probably the hibernate-jpa-version-api jar.
要解决:“无法解析导入 javax.persistence”,您需要将包含 javax.persistence.Entity 的 jar 添加到您的路径中。它可能是 hibernate-jpa-version-api jar。
To do this in Eclipse:
要在 Eclipse 中执行此操作:
- select the project from the Navigator or Package Explorer view
- From the projectmenu at the top of the screen select properties
- Click on Java Build Pathand in the libraries tab add the peristence jar
- Click OK
- 从 Navigator 或 Package Explorer 视图中选择项目
- 从屏幕顶部的项目菜单中选择属性
- 单击Java Build Path并在库选项卡中添加持久性 jar
- 单击确定
This should resolve the dependency issue you are having. If you want to add a server, go to file->new->other->server. Then choose the type of server you need.
这应该可以解决您遇到的依赖问题。如果要添加服务器,请转到file->new->other->server。然后选择您需要的服务器类型。
回答by mannedear
I have downloaded the latest Hibernate version & I got the same issue after I added the below jars only, to my project.
我已经下载了最新的 Hibernate 版本,在将以下 jars 添加到我的项目后,我遇到了同样的问题。
Folder: hibernate-search-5.8.0.Final\dist\lib\required
文件夹:hibernate-search-5.8.0.Final\dist\lib\required
Jars:
罐子:
/antlr-2.7.7.jar
/classmate-1.3.0.jar
/dom4j-1.6.1.jar
/hibernate-commons-annotations-5.0.1.Final.jar
/hibernate-core-5.2.11.Final.jar
/javassist-3.20.0-GA.jar
/jboss-logging-3.3.0.Final.jar
/lucene-core-5.5.4.jar
/lucene-queryparser-5.5.4.jar
/xml-apis-1.3.03.jar
At this stage I'm facing the below issue.
在这个阶段,我面临以下问题。
The type javax.persistence.PersistenceException cannot be resolved. It is indirectly referenced from required .class files
So I have added one more dependent jar where the code is referencing internally and the issue vanished. Folder: hibernate-search-5.8.0.Final\dist\lib\provided
因此,我又添加了一个依赖 jar,其中代码在内部引用并且问题消失了。文件夹:hibernate-search-5.8.0.Final\dist\lib\provided
Jar Name: hibernate-jpa-2.1-api-1.0.0.Final.jar
Jar 名称:hibernate-jpa-2.1-api-1.0.0.Final.jar
Please post your comments, if you have any doubts and I'm glad to answer.
请发表您的评论,如果您有任何疑问,我很乐意回答。
回答by majd hwas
I have just now arrived tofind the solution to my issue, It is because I deleted the Runtime from my project , so I had added new runtime and affected my project toIt and worked fine. Thanks all !
我刚刚到达寻找我的问题的解决方案,这是因为我从我的项目中删除了运行时,所以我添加了新的运行时并将我的项目影响到它并且工作正常。谢谢大家!