开发者

Eclipse error: "The import XXX cannot be resolved"

开发者 https://www.devze.com 2023-01-27 23:34 出处:网络
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.

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 c开发者_开发技巧lass, Eclipse says:

The import org.hibernate cannot be resolved

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

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


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.


Obviously there are cases where there is a valid issue however Eclipse throws this error for no good reason sometimes. This is still (in v 2020-09) an old (2010) Eclipse bug that can be resolved by making a negligible change to the project settings.

touch .classpath

solves the issue, or go to Project > Properties > Java Build Path > Order and Export > make a meaningless order change > Apply. Changing the order back does not regress to the problem.


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

Eclipse error: "The import XXX cannot be resolved"


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.


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.


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


  1. clean project Project - > clean...
  2. Right click on project - >BuildPath - >Configure BuildPath - >Libraries tab - >

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


This has solved my issue.

1) clean project Project -> clean...

2) Right click on project -> BuildPath -> Configure BuildPath -> Libraries tab -> Double click on JRE SYSTEM LIBRARY -> Then select alternate JRE

3) Click Save

4) Again go to your project in project explorer and right click to project -> BuildPath -> Configure BuildPath -> Libraries tab -> Double click on JRE SYSTEM LIBRARY -> This time select "Execution Environment"

5) Apply


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


I resolved this issue by updating the project: right click on the Maven project, select Maven -> Update Project -> select checkbox Force Updates of Snapshots/Releases.


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


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.

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


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.


In my case it was a broken jar in the Maven repository. Delete jar files in repository and let Maven download them again.

When I ran mvn clean install from the command line, it ran fine, but Eclipse still could not compile the code. When I ran maven install in Eclipse then I saw that Maven complained about bad jar file. So I deleted it and ran maven install again. The problem was gone.


In order to download non-existing jar file in your .m2 directory, you should run mvn clean install command for your project pom.xml. Then you should update the project dependencies by clicking Alt+F5. This works for me!


Removing the "module-info.java" did resolve the issue for me!

This file was automatically generated and did appear in my hierarchy...


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.

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


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


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.


Eclipse error: "The import XXX cannot be resolved"

If it's a Maven project, go to pom.xml and remove all the dependency jars. Save it. Project will automatically build.

Then add dependency jars again (you can do Ctrl+Z). Save it. Project will automatically build and you won't see that error.


Solution for Eclipse IDE

In my case I fixed it by correcting one of these two files that may be corrupt: .classpath or .project.

To repair any of the corrupted files, you can copy from another project that has both the .project file or .classpath file in question and is error-free. But be sure not to add additional settings that will not be used.


Remove the dependency in your POM.XML and download the jar and add it in buildpath.

sometime -> maven will not reflect new changes and this might cause this kind of prob


right-click src->new package: Rename the package that you want to import and create a new class with the package class name.
E.g if import net.proteanit.sql.DbUtils; show import error

then create a new package with the name net.proteanit.sql and make class DbUtils;

package net.proteanit.sql;
public class DbUtils {

}


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.


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.

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


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


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.


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.


I couldn't import as well. Took me some hours to figure out, that I tried to use a 1.6 bound library/jar, while I was trying to compile for 1.8. When I switched my project also to use 1.6, the import issue has gone. All error messages were leading into wrong directions. Just in the source I found some limitations directing to 1.6 version. And: For example the .settings and .classpath (File-Search) -> org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 can give a hint, on such issues.


I faced the same issue and I solved it by removing a jar which was added twice in two different dependencies on my pom.xml. Removing one of the dependency solved the issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消