为什么 Eclipse 不能识别新的 JAR?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4628345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:36:41  来源:igfitidea点击:

Why doesn't Eclipse recognize new JAR?

javaeclipseimportjar

提问by IVR Avenger

I've received a new SOAP service client JAR from a teammate, and am busy integrating it into my app. I've put the JAR into the appropriate path, overwriting the previous version. I've refreshed my workspace, performed a Clean and a Build, but...

我从队友那里收到了一个新的 SOAP 服务客户端 JAR,我正忙着将它集成到我的应用程序中。我已将 JAR 放入适当的路径,覆盖了以前的版本。我刷新了我的工作区,执行了清理和构建,但是......

...I'm not able to see any of the classes within the JAR through intellisense, even though code I utilize from the JAR will compile and execute correctly. Furthermore, Eclipse is still trying to use the previous version of the JAR, in that when I perform a "fix imports", it re-imports the old classes, rather than the new ones.

...我无法通过智能感知看到 JAR 中的任何类,即使我从 JAR 使用的代码将正确编译和执行。此外,Eclipse 仍在尝试使用先前版本的 JAR,因为当我执行“修复导入”时,它会重新导入旧类,而不是新类。

The code builds and runs, but I have to reference classes absolutely, as opposed to relatively:

代码构建并运行,但我必须绝对引用类,而不是相对:

 org.acmewidgets.soap.inputs.HeaderType header = new org.acmewidgets.soap.inputs.HeaderType()

Instead of

代替

 HeaderType header = new HeaderType()

The previous version of the JAR did not require this.

以前版本的 JAR 不需要这个。

How do I "Force" Eclipse to ditch the old references and use the new ones? Or, is Eclipse runnin' fine, and my new JAR is suspect?

我如何“强制”Eclipse 放弃旧引用并使用新引用?或者,Eclipse 运行良好,而我的新 JAR 有问题吗?

Thanks!

谢谢!

回答by Aaron Digulla

Looks like something got broken for good. If closing and opening the project again doesn't help, try this in order:

看起来有些东西永远坏了。如果再次关闭和打开项目没有帮助,请按顺序尝试:

  • If your project depends on other projects from the workspace, you could end up with twoJARs in the classpath. Run tests or your app, then switch to the "Debug" perspective, select the project (which is terminated), then select "Properties" from the context menu. This gives you the classpath which was used.

    Copy that to the text editor and search for the JAR file and make sure you only have a single copy in the classpath.

  • Search your workspace for the JAr file. Maybe there is a second copy which you don't expect.

  • Create a new workspace (don't delete the old one, yet) and import the project. Does that help?

  • Try the latest version of Eclipse (3.6.1)

  • 如果您的项目依赖于工作区中的其他项目,您可能会在类路径中得到两个JAR。运行测试或您的应用程序,然后切换到“调试”透视图,选择项目(已终止),然后从上下文菜单中选择“属性”。这为您提供了使用的类路径。

    将其复制到文本编辑器并搜索 JAR 文件并确保类路径中只有一个副本。

  • 在您的工作区中搜索 JAr 文件。也许还有您不期望的第二个副本。

  • 创建一个新的工作区(暂时不要删除旧的)并导入项目。这有帮助吗?

  • 尝试最新版本的 Eclipse (3.6.1)

回答by trojanfoe

You will have to add it as a 'User Library'.

您必须将其添加为“用户库”。