Eclipse error: "The import XXX cannot be resolved"
Solution 1
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.
Solution 2
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.
Solution 3
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.
Solution 4
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.
Solution 5
If is a Maven project, also click on Maven >> Update project... (F5)
Related videos on Youtube
bluish
I'm here to learn and to improve help retrieval about IT. #SOreadytohelp You can contact me at rumoreblu snail gmail dot com ;)
Updated on December 05, 2021Comments
-
bluish over 2 years
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:
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
-
jmj over 13 yearshow did you add these jar in your build path ?
-
bluish over 13 yearsby Properties > Java Build Path > Libraries > Add external JARs
-
Ashwin Krishnamurthy almost 9 years
-
Shanimal over 8 yearsIf it worked and they don't now, see @dogbane 's answer below...
-
schin chan almost 5 yearscheck if there is any space in your import folder. if there is a space, remove the space and import projects onto eclipse.
-
Antoine over 4 yearsClean Project did not work for me, but the good old trick of closing Eclipse and opening it again, did.
-
bluish over 4 years@Antoine You could post your solution as an answer, as it could help someone to find it and other people to vote for it
-
-
bluish over 13 yearsI've already tried this more then once: with individual jars, inside a library,... It seems an odd error!
-
Bozho over 13 yearsdo you have anything in the Problems view?
-
bluish over 13 yearsOnly the problems I told and warnings of the type "The serializable class Azienda does not declare a static final serialVersionUID field of type long".
-
dogbane over 13 yearsmight be a JRE issue. Try selecting an "alternate JRE" in the project properties.
-
Sabre Runner over 10 yearsClean also worked for me. What exactly happens (everything just went bonkers all of a sudden) and how does Clean help?
-
Zac almost 10 yearsThis solved the problem also for me; it is not an hibernate project, but a libGdx one, calling my java imports and not jars. Same wondering of @SabreRunner, and also: there is a bug somewhere in the environment tools?
-
Shanimal over 8 yearsWorked for me too. Its super frustrating when the contextual help menu is finding your class and hand typing the same import above the ones marked "cannot be resolved" and no errors...
-
Timothy.Li about 6 yearsThis way does NOT help in my case. My Eclipse version is: Neon.3 Release (4.6.3)
-
Timothy.Li about 6 yearsFile > Properties Should be changed to Project > Properties.
-
Timothy.Li about 6 yearsThis way does NOT help in my case. My Eclipse version is: Neon.3 Release (4.6.3)
-
Timothy.Li about 6 yearsIn Neon.3 Release (4.6.3), there is NO Plug-in tools in the contextual menu by right-clicking on the project in Package explorer
-
kodmanyagha almost 6 yearsIf you import a maven project as "Java project" then this problem is occur. Convert project to maven project and update as you said then the problem is gone.
-
Anthony Hayward over 5 yearsFor me, the JRE System Library had to be above the Maven Dependencies in the Build Path order&export tab.
-
user1133275 about 5 yearsThis bug is now at least 9 years old.
-
Ashu over 4 yearsFor me, install the latest eclipse with latest Oracle Java. Don't try to re-use the old eclipse workspaces.
-
Tullochgorum over 4 yearsIt's still there, Nov 2019. Sheesh.
-
Charlie over 4 yearsI removed the jar dependencies and added back again to have this problem fixed.
-
Skippy le Grand Gourou almost 4 yearsJust had the issue again, and it seems running
mvn
outsidevim
is not as efficient (that is, I tried several times without success while it worked immediately when ran throughvim
’s:Mvn
). -
bluish over 3 yearsHello Tom, I haven't read your answer, as it is very long. Please try to summarize it, or add a summary at the beginning of it, or at least highlight with bold characters the key concepts. Otherwise nobody will benefit from it. Hope you can understand, many thanks! ;)
-
Tom Rutchik over 3 yearsOh and make sure the the package you're importing is a package that is being exported in the osgi headers
-
keesp over 3 yearsWorked for me. After that changing it back to its original settings gave no problems. cleaning was not necessary (with Eclipse 2020-12)
-
tonyfarney about 3 yearsIt worked for me, for a PHP project. Before I do the clean operation I've been add composer support and rebuild, but didn't work.
-
briancollins081 over 2 yearsThis does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
-
bluish over 2 years@ItzToxic, this is a question about Eclipse and Java. You talk about vscode and Python... please delete your answer ;)
-
MD. RAKIB HASAN over 2 yearsYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-
GaidinD over 2 yearsThis fixed it for me. It was set to 15 for me. But the project was built to compliance level 1.8.