我可以阻止 javac 从第三方 jar 的清单访问类路径吗?
从 Java 1.5 左右开始,javac 一直在查看第三方 jar 的清单以查找其他 jar。这会导致许多不良的副作用:
- 由于 jar 文件已被重命名,现在每当我们编译时都会收到大量警告(可以使用
-Xlint:-path
禁用) - 我们不编译的文件即使它们由于某种原因被排除在外,也会被带回到类路径上。
- 由于我们实际上并不想要这些东西的分辨率,因此在构建中需要花费额外的时间来查找所有这些额外的 jar。
所以我想知道是否有人知道禁用此功能的魔法调用。假设 Sun 没有给我们提供其他我们不想要的功能,并且一旦我们拥有它就无法关闭。
Since Java 1.5 or so, javac has been looking into the manifest of third-party jars to find other jars. This causes a number of undesirable side-effects:
- As jar files have been renamed, we now get a flood of warnings whenever we compile (can be diabled with
-Xlint:-path
) - Files we don't want on the classpath are being brought back onto it, even if they were left off it for a reason.
- Additional time is being taken in the build to look up all these additional jars, due to the resolution of this stuff we don't actually want.
So I was wondering if anyone knows the magic invocation to disable this. Assuming that Sun didn't saddle us with another feature we didn't want and can't turn off once we have it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个修改清单文件的 Ant 目标(使用 ant-contrib)
Heres an Ant target to modify the manifest files(uses ant-contrib)
使用 bnd 或 Shadow 从 jar 中删除有问题的 MANIFEST.MF 条目,而不仅仅是重命名。或者利用这些路径名本质上从来都不是绝对的这一点。如果将名为“i-have-a-ClassPath.jar”的 jar 移动到其自己的子目录中,清单类路径条目将无法在预期位置找到这些其他 jar。不过,我想如果你打开足够多的棉绒,它仍然会发出抱怨声。
Use bnd or shade to strip the offending MANIFEST.MF entry from the jars, instead of just renaming. Or take advantage of the face that these pathnames are essentially never absolute. If you move the jar named 'i-have-a-ClassPath.jar' into its own subdirectory, the manifest class path entries will fail to find these other jars in the expected locations. I suppose that will still whine if you turn on enough lint, though.