3

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.

spongebob
  • 8,370
  • 15
  • 50
  • 83
DonyorM
  • 1,760
  • 1
  • 20
  • 34
  • maybe cleaning your project first and then trying import might help – vikeng21 Dec 19 '14 at 10:09
  • @vikeng21 hmmm. Didn't work. It's maybe more of a java issue or something, because it is a problem in both netbeans and eclipse – DonyorM Dec 19 '14 at 10:11
  • you already download again API from spigotmc.org or another latest version will be solution? – Ye Win Dec 19 '14 at 10:16
  • @YeWin It's the newest version, that's practically the first thing I tried. – DonyorM Dec 19 '14 at 10:17
  • You can try writing the import manually, or removing and re-importing the library. Or then recreating the project completely. – Bubletan Dec 19 '14 at 10:18
  • @Bubletan I've done all of those things, in fact, I did the last in two different IDEs. I've even used two slightly different (but for the purposes of this post, equivalent) libraries. – DonyorM Dec 19 '14 at 10:19
  • @DonyorM And are you sure, there are no dependency conflicts in your project? – SSC Dec 19 '14 at 10:28
  • @Mr.777 I only have one referenced library (dependency) in my project. That an the Java SE. So yes, I am sure. – DonyorM Dec 19 '14 at 10:29
  • Then 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 – SSC Dec 19 '14 at 10:33
  • @Mr.777 Ok, just finished. I feel a little stupid now. The class was mark with package level visibility only. Do you want to add something to that extent as an answer? I'll mark it as accepted since you helped me find the issue. – DonyorM Dec 19 '14 at 10:57
  • Do you want me to add that as answer? :) – SSC Dec 19 '14 at 10:57
  • @Mr.777 Sure, go ahead. – DonyorM Dec 19 '14 at 10:58

2 Answers2

2

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.

SSC
  • 2,956
  • 3
  • 27
  • 43
0

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.

Vincent F
  • 6,523
  • 7
  • 37
  • 79