简体   繁体   中英

Eclipse is showing me the jar, but I'm unable to use the classes in it

I'm building an existing project with Maven in Eclipse and all the dependencies are downloaded. But some of my classes using some classes from a specific jar are not found : the import statement shows an error.

The strange thing is that when I browse the Maven dependencies in Eclipse, I see the jar. I'm also able to unfold the jar, and browse in the packages, and see the classes in it. So as far as I can say, the jar is here in my classpath, available to my project. But somehow, it's not seen by my code. I've tried rebuilding, from Eclipse and from mvn command line, but I still have the same issue.

Any idea where that issue could come from ?

Thanks

One root cause would be that your jar is corrupted . Not corrupted enough to make it unavailable in Eclipse, but corrupted enough to prevent Eclipse from using the classes inside.

To make sure of this :

  • go to your local Maven repo, where the jar is supposed to be.
  • try to open the jar with your zip tool (Winzip or equivalent)

if you get an error saying your jar is corrupted, then all you have to do is delete the directory containing the corrupted jar, and build again your project with Maven : jar file would be downloaded again from your remote Maven repository.

If this time you're able to open it, then probably Eclipse will also, and you'll be able to use the classes inside and your problem will be solved. If you're still unable to open it, check if the jar is not corrupted on central repository itself.

Had you add the jar file to your Build Path, if not, then you can not find the classes in the jar file.

Try to do this: In Eclipse:

Right click on the jar file  --> Build Path  --> Add to Build Path.

Then try again if you can find the classes in the jar file or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM