Why doesn't Eclipse recognize new JAR?

2019-07-02 00:40发布

问题:

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...

...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.

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.

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?

Thanks!

回答1:

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 two JARs 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)



回答2:

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