简体   繁体   English

Eclipse不显示外部JAR文件中的类

[英]Eclipse not showing classes from an external JAR file

I am currently trying to develop a plugin using the Bukkit API in Eclipse. 我目前正在尝试使用Eclipse中的Bukkit API开发插件。 However, it seems I cannot import specific classes from the API jar file. 但是,似乎我无法从API jar文件中导入特定的类。 If I open the jar file up and look in the list of classes, the classes are there. 如果我打开jar文件并查看类列表,那么这些类就在那里。 However, eclipse will not accept import of those classes into my own classes. 但是,eclipse不会接受将这些类导入到我自己的类中。 It shows an error denoting: 它显示一个错误表示:

[classname] cannot be resolved to a type [classname]无法解析为某个类型

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). 使用Bukkit API的其他开发人员没有这个问题(我特别要求)。

Picture showing error: 图片显示错误:

The class EntityEnderman is in the same package as the class PathfinderGoalEndermanPickupBlock . EntityEnderman类与类PathfinderGoalEndermanPickupBlock位于同一个包中。 But EntityEnderman is properly imported, PathfinderGoalEndermanPickupBlock is not. EntityEnderman是正确导入的, PathfinderGoalEndermanPickupBlock不是。

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. 我正在使用spigotmc.org上的1.8版API。 I am using the newest eclipse available from the Linux Mint repository (Eclipse 3.8). 我正在使用Linux Mint存储库(Eclipse 3.8)中提供的最新eclipse。 This same error occurs in Netbeans 8, however. 但是,Netbeans 8中也会出现同样的错误。

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. 你可以尝试一件事,提取jar并将提取的文件放在你的代码中[我知道这是最糟糕的解决方案]但只是为了接近知道究竟是什么错误。

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. 本周我有类似的问题:jar在Eclipse中显示,我可以“看到”其中的类,但是无法在我的代码中导入类,与您类似的错误。

Turns out the jar was corrupted in my local maven repo : I wasn't able to open it (with winzip). 结果我的本地maven回购中的jar已损坏:我无法打开它(使用winzip)。 Fixing this was as easy as deleting the jar's version directory in my local repo, and building the app again. 解决这个问题就像在我的本地仓库中删除jar的版本目录一样简单,并再次构建应用程序。 This time, jar got downloaded correctly, and I was able to use the classes from it. 这次,jar被正确下载,我能够使用它的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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