简体   繁体   中英

Eclipse not showing classes from an external JAR file

I am currently trying to develop a plugin using the Bukkit API in Eclipse. However, it seems I cannot import specific classes from the API jar file. If I open the jar file up and look in the list of classes, the classes are there. However, eclipse will not accept import of those classes into my own classes. It shows an error denoting:

[classname] cannot be resolved to a type

I see no reason why the class should not be accepted. Other classes from the same package are imported properly. Other developers using the Bukkit API do not have this problem (I specifically asked).

Picture showing error:

The class EntityEnderman is in the same package as the class PathfinderGoalEndermanPickupBlock . But EntityEnderman is properly imported, PathfinderGoalEndermanPickupBlock is not.

Here's a picture showing what happens if I click the Fix Project Setup option:

I have already tried to manually edit the build path.

Picture showing proof that the class is really added to the build path of the project:

Why would this happen, and how can I fix it?

I am using the 1.8 version of the API found at spigotmc.org. I am using the newest eclipse available from the Linux Mint repository (Eclipse 3.8). This same error occurs in Netbeans 8, however.

First things first:

Are you sure, there are no dependency conflicts in your project?

If not, [as per your comments]

You can try one more thing, extract the jar and place the extracted files within your code [I know it's the worst solution to do] but just for the sake of getting close to know what exactly is wrong.

Also, as you have mentioned that class is marked as package level visibility so you can not really use it outside the package.

I had similar issue this week : jar was showing in Eclipse, and I could "see" the classes in it, but impossible to import the classes in my code, similar errors as you.

Turns out the jar was corrupted in my local maven repo : I wasn't able to open it (with winzip). Fixing this was as easy as deleting the jar's version directory in my local repo, and building the app again. This time, jar got downloaded correctly, and I was able to use the classes from it.

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