Eclipse:未选择引用库 .jar 的更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17041038/
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 20:42:30  来源:igfitidea点击:

Eclipse: updates to referenced library .jar not picked up

javaeclipsejar

提问by Dave W

I have 2 Java projects in my Eclipse workspace, as follows:

我的 Eclipse 工作区中有 2 个 Java 项目,如下所示:

One is a library of code that automatically creates a .jar file whenever it builds.

一个是代码库,它在构建时自动创建一个 .jar 文件。

The other is an application that uses classes in that library, and references the .jar file created by the library project (by right-clicking the app -> Build Path -> Configure Build Path -> Libraries -> Add JARs...)

另一个是使用该库中的类的应用程序,并引用由库项目创建的 .jar 文件(通过右键单击应用程序 -> 构建路径 -> 配置构建路径 -> 库 -> 添加 JAR...)

However, whenever I modify classes in my library project, although I can see that the library .jar gets updated, the app project doesn't pick up the changes unless I remove the library .jar from the app's referenced libraries and re-add it

但是,每当我修改库项目中的类时,虽然我可以看到库 .jar 已更新,但除非我从应用程序引用的库中删除库 .jar 并重新添加它,否则应用程序项目不会获取更改

Am I fundamentally doing something wrong? Is there perhaps a better way to connect an app to a shared library of code? How can I make sure my app will always refer to the latest library code?

我从根本上做错了吗?是否有更好的方法将应用程序连接到共享代码库?如何确保我的应用始终引用最新的库代码?

回答by Matthew Kirkley

Instead of adding it as a JAR dependency you could add it as a project dependency. Right click your project and go to properties. Click on 'Java Build Path' and select the 'Projects' tab. Click 'Add..." and add your library project.

您可以将其添加为项目依赖项,而不是将其添加为 JAR 依赖项。右键单击您的项目并转到属性。单击“Java 构建路径”并选择“项目”选项卡。单击“添加...”并添加您的库项目。

回答by josephus

With the latest Eclipse (I'm sure it also worked the same with the ones before), doing a refresh and Clean on your library project then on your application will update the libraries referenced.

使用最新的 Eclipse(我确定它也与之前的相同),对您的库项目进行刷新和清理,然后在您的应用程序上将更新引用的库。