Eclipse错误:“导入XXX无法解决”

时间:2023-01-18 11:19:40

I'm trying to work with Hibernate in Eclipse. I'm creating a new simple project and I've downloaded a collegue project too, via CVS. Both don't work, while on my collegue's Eclipse do. The problem is that, for each import of an Hibernate class, Eclipse says:

我正在尝试在Eclipse中使用Hibernate。我正在创建一个新的简单的项目,我也通过CVS下载了一个collegue项目。两者都不工作,而在我的同事的Eclipse中。问题是,对于每个Hibernate类的导入,Eclipse说:

The import org.hibernate cannot be resolved

But all Hibernate jars are in the build path, that is:

但是所有Hibernate jar都在构建路径中,即:

antlr-2.7.6.jar
cglib-2.2.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
hibernate3.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-1.6.1.jar

22 个解决方案

#1


229  

Try cleaning your project by going to the following menu item:

试着通过以下菜单来清洁你的项目:

Project > Clean...

If that doesn't work, try removing the jars from the build path and adding them again.

如果这不起作用,可以尝试从构建路径删除jar并再次添加它们。

#2


17  

Clean the project. And double-check the jars being really on the build path (with no errors). Also make sure there is nothing in the "Problems" view.

清洁项目。再次检查在构建路径上的jar(没有错误)。还要确保在“问题”视图中没有任何内容。

#3


16  

This still (2017) seems to be an old (2010) Eclipse bug that can be resolved by making a negligible change to the project settings.

这个仍然(2017)似乎是一个旧的(2010)Eclipse bug,可以通过对项目设置做一个可忽略的更改来解决。

The setting I chose to change was: File > Properties > Java Build Path > Order and Export > make a meaningless order change > Apply.

我选择更改的设置是:>属性> Java构建路径>订单和Export >做一个无意义的订单更改>应用。

Changing the order back does not regress to the problem. Simply touching the file might also resolve the issue (I'll test touch next time).

更改订单返回不会退回到问题。简单地触摸文件也可以解决这个问题(下次我将测试触摸)。

#4


14  

I found the problem. It was the hibernate3.jar. I don't know why it was not well extracted from the .zip, maybe corrupt. A good way to check if jars are corrupt or not is navigating through their tree structure in "Project Explorer" in Eclipse: if you can't expand a jar node probably it's corrupt. I've seen that having corrupt packages it's frequent when you drag and drop them to the "Project Explorer". Maybe it's better to move and copy them in the OS environment! Thankyou all.

我发现这个问题。hibernate3.jar。我不知道为什么它不能从。zip中提取出来,可能是腐败。一个检查jar是否损坏的好方法是在Eclipse中“Project Explorer”中的树结构中导航:如果您不能展开一个jar节点,那么它可能是腐败的。我曾经看到过,当你把它们拖放到“Project Explorer”上时,它经常会出现损坏。也许最好在操作系统环境中移动和复制它们!谢谢所有人。

#5


6  

If is a Maven project, also click on Maven >> Update project... (F5)

如果是一个Maven项目,也可以单击Maven >>更新项目……(F5)

Eclipse错误:“导入XXX无法解决”

#6


5  

I had the problem, that the classpath was broken somehow.

我有个问题,类路径被破坏了。

So right click on the project in Package explorer > Plug-in tools > Update classpath... did it for me

所以右键单击Package explorer >插件工具>更新类路径…为我做的

#7


3  

Try adding JRE System Library in the build path of your project.

尝试在项目的构建路径中添加JRE系统库。

#8


2  

I solved it by removing the project (do not delete on the disk) and importing it again.

我通过删除项目(不要在磁盘上删除)并再次导入它来解决它。

#9


1  

I had the same problem because I added a jar I created, where I had set the packaging base directory other than the base directory of the classes. As a result the class e.g. java.util.List had to be imported as util.List although the suggested import was the first one.

我遇到了同样的问题,因为我添加了一个我创建的jar,在那里我设置了除了类的基本目录之外的打包基目录。因此,类,例如java.util。列表必须作为util导入。列表虽然建议的导入是第一个。

Check the imported jars under referenced libraries to see that they are imported correctly

检查引用库下的导入的jar,看看它们是否正确导入。

#10


1  

I didn't understand the reasoning behind this but this solved the same problem I was facing. You may require these steps before executing steps mentioned in above solutions (Clean all projects and Build automatically).

我不明白这背后的原因,但这解决了我所面临的同样的问题。在执行上述解决方案中提到的步骤之前,您可能需要这些步骤(清理所有项目并自动构建)。

right click project -> Properties -> Project Facets -> select Java -> Apply

右击项目->属性->项目facet ->选择Java ->应用。

#11


1  

Whenever you come across this problem just go to Project > Clean, then select Clean all projects. It should get resolved, otherwise try to delete those jars and add them again. Last thing would be to try restarting Eclipse.

无论什么时候遇到这个问题,只要去>项目清理,然后选择干净的所有项目。它应该被解析,否则尝试删除这些jar并再次添加它们。最后一件事是尝试重新启动Eclipse。

#12


1  

  1. clean project Project - > clean...
  2. 清洁项目项目- >清洁…
  3. Right click on project - >BuildPath - >Configure BuildPath - >Libraries tab - >
  4. 右键单击project - >BuildPath - >配置BuildPath - >库标签- >。

Double click on JRE SYSTEM LIBRARY - >Then select alternate JRE

双击JRE系统库- >然后选择备用JRE。

#13


1  

I tried all of the answers above but no luck. In my case, there is a generated build/classes folder with some additional ".class" files. I ended up going to the package explorer, right-clicking on the project and selecting the "Refresh" option and that made the build/classes folder available again resolving the issue.

我尝试了以上所有的答案,但没有成功。在我的例子中,有一个生成的构建/类文件夹,带有一些额外的“。阶级”文件。我最终选择了package explorer,右键单击项目并选择“Refresh”选项,并使build/classes文件夹能够再次解决这个问题。

#14


0  

Please try and check whether all the libs are in place. I had the same issue. But I solved it by moving the lib folder and adding all the jars again in the build path.

请试着检查是否所有的libs都到位了。我有同样的问题。但是我通过移动lib文件夹并在构建路径中再次添加所有jar来解决它。

#15


0  

I got the same problem. I downloaded the jar and added it to the build path, but I didn't notice that the extension was .jar.zip. I again converted it to .jar and added to the build path.

我遇到了同样的问题。我下载了这个jar,并将它添加到构建路径中,但是我没有注意到扩展名是.jar.zip。我再次将其转换为.jar并添加到构建路径中。

It solved my problem. It's a very silly mistake but I wrote it here in case it could help someone.

它解决了我的问题。这是一个非常愚蠢的错误,但我在这里写了,以防它能帮助到别人。

#16


0  

I solved this problem using the JPA JAR from Maven repository, adding it on the build path of project.

我使用Maven存储库中的JPA JAR解决了这个问题,并将它添加到项目的构建路径中。

#17


0  

If you are working with Maven and have this problem, check the repository server (for example nexus server), if the artifact is there. Sometimes, they can change the name of the artifact and you try to get the artifact with its old name.

如果您正在与Maven一起工作,并且有这个问题,请检查存储库服务器(例如,nexus服务器),如果工件在那里。有时,它们可以更改工件的名称,并尝试使用它的旧名称来获得工件。

#18


0  

Resolved by linking the source. From the explorer right click on the project, select properties, select Java Build Path, select Source from tabs, press button "LinkSource". And specifying the folder to add to the project.

通过链接源来解决。从资源管理器右键单击项目,选择properties,选择Java构建路径,从选项卡中选择Source,按下按钮“LinkSource”。并指定要添加到项目的文件夹。

#19


0  

With me it helped changing the compiler compliance level. For unknown reasons it was set to 1.6 and I changed it to 1.8.

对我来说,它有助于改变编译器的遵从性水平。由于未知的原因,它被设置为1.6,而我将它改为1.8。

Once at project level right click on project > Properties > Java Compiler, while in Eclipse click on menu Window > Preferences > Java > Compiler.

一旦在项目级别右击项目>属性> Java编译器,而在Eclipse中单击菜单窗口>首选项> Java >编译器。

#20


-1  

Check If Your POM file is Updated with same Version in all Modules.

检查您的POM文件是否在所有模块中都有相同版本的更新。

#21


-2  

For me,

对我来说,

Project ---> Source ---> Format

项目——>源代码——>格式。

solved the problem

解决了这个问题

#22


-2  

If you're developing plugins in eclipse and you're using a target platform (which was my case) you need to make sure you check the target's platform configuration from Window->Preferences->Plug-in Development->Target Platform and make sure your target platform is checked and configured. Hope this helps.

如果您正在eclipse中开发插件,并且您正在使用目标平台(这是我的情况),您需要确保从窗口->首选项->插件开发->目标平台检查目标平台配置,并确保您的目标平台已被检查和配置。希望这个有帮助。

#1


229  

Try cleaning your project by going to the following menu item:

试着通过以下菜单来清洁你的项目:

Project > Clean...

If that doesn't work, try removing the jars from the build path and adding them again.

如果这不起作用,可以尝试从构建路径删除jar并再次添加它们。

#2


17  

Clean the project. And double-check the jars being really on the build path (with no errors). Also make sure there is nothing in the "Problems" view.

清洁项目。再次检查在构建路径上的jar(没有错误)。还要确保在“问题”视图中没有任何内容。

#3


16  

This still (2017) seems to be an old (2010) Eclipse bug that can be resolved by making a negligible change to the project settings.

这个仍然(2017)似乎是一个旧的(2010)Eclipse bug,可以通过对项目设置做一个可忽略的更改来解决。

The setting I chose to change was: File > Properties > Java Build Path > Order and Export > make a meaningless order change > Apply.

我选择更改的设置是:>属性> Java构建路径>订单和Export >做一个无意义的订单更改>应用。

Changing the order back does not regress to the problem. Simply touching the file might also resolve the issue (I'll test touch next time).

更改订单返回不会退回到问题。简单地触摸文件也可以解决这个问题(下次我将测试触摸)。

#4


14  

I found the problem. It was the hibernate3.jar. I don't know why it was not well extracted from the .zip, maybe corrupt. A good way to check if jars are corrupt or not is navigating through their tree structure in "Project Explorer" in Eclipse: if you can't expand a jar node probably it's corrupt. I've seen that having corrupt packages it's frequent when you drag and drop them to the "Project Explorer". Maybe it's better to move and copy them in the OS environment! Thankyou all.

我发现这个问题。hibernate3.jar。我不知道为什么它不能从。zip中提取出来,可能是腐败。一个检查jar是否损坏的好方法是在Eclipse中“Project Explorer”中的树结构中导航:如果您不能展开一个jar节点,那么它可能是腐败的。我曾经看到过,当你把它们拖放到“Project Explorer”上时,它经常会出现损坏。也许最好在操作系统环境中移动和复制它们!谢谢所有人。

#5


6  

If is a Maven project, also click on Maven >> Update project... (F5)

如果是一个Maven项目,也可以单击Maven >>更新项目……(F5)

Eclipse错误:“导入XXX无法解决”

#6


5  

I had the problem, that the classpath was broken somehow.

我有个问题,类路径被破坏了。

So right click on the project in Package explorer > Plug-in tools > Update classpath... did it for me

所以右键单击Package explorer >插件工具>更新类路径…为我做的

#7


3  

Try adding JRE System Library in the build path of your project.

尝试在项目的构建路径中添加JRE系统库。

#8


2  

I solved it by removing the project (do not delete on the disk) and importing it again.

我通过删除项目(不要在磁盘上删除)并再次导入它来解决它。

#9


1  

I had the same problem because I added a jar I created, where I had set the packaging base directory other than the base directory of the classes. As a result the class e.g. java.util.List had to be imported as util.List although the suggested import was the first one.

我遇到了同样的问题,因为我添加了一个我创建的jar,在那里我设置了除了类的基本目录之外的打包基目录。因此,类,例如java.util。列表必须作为util导入。列表虽然建议的导入是第一个。

Check the imported jars under referenced libraries to see that they are imported correctly

检查引用库下的导入的jar,看看它们是否正确导入。

#10


1  

I didn't understand the reasoning behind this but this solved the same problem I was facing. You may require these steps before executing steps mentioned in above solutions (Clean all projects and Build automatically).

我不明白这背后的原因,但这解决了我所面临的同样的问题。在执行上述解决方案中提到的步骤之前,您可能需要这些步骤(清理所有项目并自动构建)。

right click project -> Properties -> Project Facets -> select Java -> Apply

右击项目->属性->项目facet ->选择Java ->应用。

#11


1  

Whenever you come across this problem just go to Project > Clean, then select Clean all projects. It should get resolved, otherwise try to delete those jars and add them again. Last thing would be to try restarting Eclipse.

无论什么时候遇到这个问题,只要去>项目清理,然后选择干净的所有项目。它应该被解析,否则尝试删除这些jar并再次添加它们。最后一件事是尝试重新启动Eclipse。

#12


1  

  1. clean project Project - > clean...
  2. 清洁项目项目- >清洁…
  3. Right click on project - >BuildPath - >Configure BuildPath - >Libraries tab - >
  4. 右键单击project - >BuildPath - >配置BuildPath - >库标签- >。

Double click on JRE SYSTEM LIBRARY - >Then select alternate JRE

双击JRE系统库- >然后选择备用JRE。

#13


1  

I tried all of the answers above but no luck. In my case, there is a generated build/classes folder with some additional ".class" files. I ended up going to the package explorer, right-clicking on the project and selecting the "Refresh" option and that made the build/classes folder available again resolving the issue.

我尝试了以上所有的答案,但没有成功。在我的例子中,有一个生成的构建/类文件夹,带有一些额外的“。阶级”文件。我最终选择了package explorer,右键单击项目并选择“Refresh”选项,并使build/classes文件夹能够再次解决这个问题。

#14


0  

Please try and check whether all the libs are in place. I had the same issue. But I solved it by moving the lib folder and adding all the jars again in the build path.

请试着检查是否所有的libs都到位了。我有同样的问题。但是我通过移动lib文件夹并在构建路径中再次添加所有jar来解决它。

#15


0  

I got the same problem. I downloaded the jar and added it to the build path, but I didn't notice that the extension was .jar.zip. I again converted it to .jar and added to the build path.

我遇到了同样的问题。我下载了这个jar,并将它添加到构建路径中,但是我没有注意到扩展名是.jar.zip。我再次将其转换为.jar并添加到构建路径中。

It solved my problem. It's a very silly mistake but I wrote it here in case it could help someone.

它解决了我的问题。这是一个非常愚蠢的错误,但我在这里写了,以防它能帮助到别人。

#16


0  

I solved this problem using the JPA JAR from Maven repository, adding it on the build path of project.

我使用Maven存储库中的JPA JAR解决了这个问题,并将它添加到项目的构建路径中。

#17


0  

If you are working with Maven and have this problem, check the repository server (for example nexus server), if the artifact is there. Sometimes, they can change the name of the artifact and you try to get the artifact with its old name.

如果您正在与Maven一起工作,并且有这个问题,请检查存储库服务器(例如,nexus服务器),如果工件在那里。有时,它们可以更改工件的名称,并尝试使用它的旧名称来获得工件。

#18


0  

Resolved by linking the source. From the explorer right click on the project, select properties, select Java Build Path, select Source from tabs, press button "LinkSource". And specifying the folder to add to the project.

通过链接源来解决。从资源管理器右键单击项目,选择properties,选择Java构建路径,从选项卡中选择Source,按下按钮“LinkSource”。并指定要添加到项目的文件夹。

#19


0  

With me it helped changing the compiler compliance level. For unknown reasons it was set to 1.6 and I changed it to 1.8.

对我来说,它有助于改变编译器的遵从性水平。由于未知的原因,它被设置为1.6,而我将它改为1.8。

Once at project level right click on project > Properties > Java Compiler, while in Eclipse click on menu Window > Preferences > Java > Compiler.

一旦在项目级别右击项目>属性> Java编译器,而在Eclipse中单击菜单窗口>首选项> Java >编译器。

#20


-1  

Check If Your POM file is Updated with same Version in all Modules.

检查您的POM文件是否在所有模块中都有相同版本的更新。

#21


-2  

For me,

对我来说,

Project ---> Source ---> Format

项目——>源代码——>格式。

solved the problem

解决了这个问题

#22


-2  

If you're developing plugins in eclipse and you're using a target platform (which was my case) you need to make sure you check the target's platform configuration from Window->Preferences->Plug-in Development->Target Platform and make sure your target platform is checked and configured. Hope this helps.

如果您正在eclipse中开发插件,并且您正在使用目标平台(这是我的情况),您需要确保从窗口->首选项->插件开发->目标平台检查目标平台配置,并确保您的目标平台已被检查和配置。希望这个有帮助。