重新编译Jar依赖
假设我有一个项目依赖于 JAR A 中的类,该项目随后依赖于 JAR B 中的类。要运行该项目,两个 jar 需要位于同一类路径上。我有所有三个部分的源代码 - 项目、JAR A 和 JAR B。
如果我更改 JAR B 中类中方法的内部而不更改 API,我是否需要针对它重新编译 JAR A,或者可以我只是将它放入项目的类路径中然后就可以了?
如果我考虑一下,我认为我不需要,但我只是想仔细检查一下。当我只是尝试向 JAR B 添加额外的日志记录(这对 JAR A 没有影响)时,一直复制文件是非常烦人的。
Let's say I have a project with a dependency on a class in JAR A, which subsequently has a dependency on a class in JAR B. To run the project, both jars need to be on the same class path. I have the source code for all three pieces - project, JAR A, and JAR B.
If I change the internals of the method in the class in JAR B without changing the API, do I need to recompile JAR A against it, or can I just drop it into the classpath of the project and go?
If I think about it, I don't think I would need to but I just want to double check. It's quite annoying copying the files around all the time when I'm just trying to add extra logging to JAR B which has no effect on JAR A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你是对的:你只需重新创建包含新类的 JAR B 并将其与 JAR A 和 C 一起放入类路径中。
I think you're correct: you'd simply re-create the JAR B that contained the new class and put it in the class path along with JARs A and C.
填充 Jar A 的代码只需要能够编译即可创建该 jar。
如果它依赖 Jar B 进行编译,那么 Jar B 的存在需要满足 Jar A 的代码对其进行的所有引用。
反之亦然。
一旦 Jar A 的代码编译完毕,您就可以创建它的 jar 并忘记它。
然后,您可以随意更改 Jar B,只要 Jar A 使用的 API 不发生更改即可。
EG:
在 Jar B 中定义一个函数:
这会编译并且您可以创建 Jar B。
在 Jar A 中您引用该函数:
这会编译并且您可以创建 Jar A,但是运行它会抛出异常。
您可以更新 Jar B 代码:
这将编译并且您可以重新创建 Jar B。Jar A 可以毫无异常地运行。
但是,如果您更新 Jar B 并更改 API:
您将需要修改并重新编译 Jar A。
the code which populates Jar A only needs to be able to compile in order to create the jar.
If it relies on Jar B to compile, then Jar B needs to exist to the extent that it satisfies all of the references made to it by the code for Jar A.
The opposite is also true.
Once the code for Jar A has compiled, you can create it's jar and forget about it.
You can then change Jar B as much as you like as long as the API Jar A uses doesn't change.
EG:
In Jar B you define a function:
This compiles and you can create Jar B.
In Jar A you reference the function:
This compiles and you can create Jar A, however running it would throw an exception.
You can update your Jar B code:
This compiles and you can re-create Jar B. Jar A can run without exception.
However if you update Jar B and change the API:
You will need to modify and recompile Jar A.