gpt4 book ai didi

java - 声明 maven 对 tools.jar 的依赖以在 JDK 9 上工作

转载 作者:行者123 更新时间:2023-12-01 16:28:34 25 4
gpt4 key购买 nike

我有一个使用 this technique 的项目在 JDK 8 及更早版本中运行良好。然而,在 JDK 9 中,这个 jar 被删除并且不再起作用:

'dependencies.dependency.systemPath' for com.sun:tools:jar refers to a non-existing file /usr/lib/jvm/java-9-jdk/../lib/tools.jar. Please verify that you run Maven using a JDK and not just a JRE.

(路径看起来很奇怪,尽管没有tools.jar in JDK 9)

跨 JDK 版本甚至 JDK 供应商的最佳实践是什么?我什至没有在 OpenJDK 上找到 JDK 9 的任何解决方法(同时保持项目可在 JDK 8 上构建)。

最佳答案

您的问题是由 Project Jigsaw 引起的您似乎已经使用过 Java 9 EA 构建中的更改。 JEP 220描述它们。

已删除:rt.jartools.jar 部分更详细地描述了这一点,但风险和假设 包含一个很好的总结:

JDK and JRE images will, as noted above, no longer contain the files lib/rt.jar, lib/tools.jar, lib/dt.jar, and other internal jar files. Existing code that assumes the existence of these files might not work correctly.

正如您所观察到的,这些文件已经消失了。再往下:

Class and resource files previously found in lib/tools.jar and visible only when that file was added to the class path will now, in a JDK image, be visible via the system class loader or, in some cases, the bootstrap class loader. The modules containing these files will not, however, be mentioned in the application class path, i.e., in the value of the system property java.class.path.

因此,tools.jar 中的类已移至模块中,但用户似乎无法使用它们。您应该使用 jdeps来自最近的 Jigsaw 构建...

  • ...确定您的模块依赖项:$jdeps -M -s $your_JAR
  • ...确定 JDK 内部 API 的依赖关系:jdeps -jdkinternals $your_JAR

如果您幸运的话,您正在使用的 API 已发布(那么它将不会出现在第二次分析中)或者有一个公共(public)替代方案(第二次分析将列出)。否则,您应该考虑将其发送至 Jigsaw mailing list并在那里寻求帮助,明确指出您正在使用哪些 API 以及用途。

关于java - 声明 maven 对 tools.jar 的依赖以在 JDK 9 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62103992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com