声明对tools.jar的maven依赖以在JDK 9上工作 [英] Declare maven dependency on tools.jar to work on JDK 9
问题描述
我有一个使用此技术的项目,该项目在JDK中效果很好8岁以上.但是,在JDK 9中,此jar已被删除,并且不再起作用:
I have a project that uses this technique that work fine in JDK 8 and older. However, in JDK 9 this jar was removed and it does no longer work:
com.sun:tools:jar的'dependencies.dependency.systemPath'指的是不存在的文件/usr/lib/jvm/java-9-jdk/../lib/tools.jar.请验证您使用JDK而不是JRE运行Maven.
'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.
(The path looks strange, though there is no tools.jar in JDK 9)
在所有JDK版本甚至JDK供应商中都可以使用的最佳实践是什么?我什至没有在OpenJDK上找到针对JDK 9的任何解决方法(同时使项目可在JDK 8上构建).
What is the best practice that would work across JDK versions and perhaps even JDK vendors? I have not even found any workaround for JDK 9 on OpenJDK (while keeping the project buildable on JDK 8).
推荐答案
您的问题是由项目引起的您似乎使用过的Java 9 EA构建中的Jigsaw 更改. JEP 220 描述了它们.
Your problems are caused by the Project Jigsaw changes that went into the Java 9 EA build you seem to have used. JEP 220 describes them.
已删除部分:rt.jar
和tools.jar
部分对此进行了更详细的描述,但风险和假设包含一个很好的摘要:
The section Removed: rt.jar
and tools.jar
describes this in more detail but Risks and Assumptions contains a good summary:
如上所述,JDK和JRE映像将不再包含文件
lib/rt.jar
,lib/tools.jar
,lib/dt.jar
和其他内部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.
因此,如您所见,这些文件都消失了.往下走:
So as you observed, those files are gone. Further down:
以前在
lib/tools.jar
中找到并且仅在将该文件添加到类路径时才可见的类和资源文件,现在将在JDK图像中通过系统类加载器或在某些情况下通过引导类加载器可见.但是,在应用程序类路径即中,系统属性java.class.path
的值中不会提及包含这些文件的模块.
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 propertyjava.class.path
.
因此,tools.jar
中的类已移入模块,但似乎它们可能对用户不可用.您应该使用最近的Jigsaw版本中的 jdeps ...
So the classes from tools.jar
are moved into modules but it seems like they might not be available to the user. You should use jdeps from a recent Jigsaw build...
- ...确定您的模块依赖性:
$jdeps -M -s $your_JAR
- ...确定对JDK内部API的依赖关系:
jdeps -jdkinternals $your_JAR
- ... to determine your module dependencies:
$jdeps -M -s $your_JAR
- ... to determine dependencies on JDK-internal APIs:
jdeps -jdkinternals $your_JAR
如果幸运的话,您所使用的API已发布(然后它不会显示在第二个分析中)或有一个公共替代项(第二个分析将列出该API).否则,您应该考虑将其带到拼图邮件列表并寻求帮助在那里,明确指出您正在使用哪些API,以及用于什么.
If you're lucky, the API you are using was published (then it will not show up in the second analysis) or have a public alternative (which the second analysis would list ). Otherwise you should consider taking this to the Jigsaw mailing list and ask for help there, noting explicitly which APIs you are using and what for.
这篇关于声明对tools.jar的maven依赖以在JDK 9上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!