【发布时间】:2021-02-17 15:14:56
【问题描述】:
我最近一直在使用测试自动化。
我现在熟悉了几种工具、框架、依赖项等,例如 Selenium、JUNits、TestNG,它们可以帮助我管理我作为 QA 工程师的日常工作。
我经常使用 Selenium 和 TestNG 来构建我的解决方案,以及在最新 JDK 版本 (jdk-15.0.1) 上运行的 IntelliJ IDEA Mac 在 macOS Catalina 版本 10.15.7 上运行。
我已经为我的项目配置了 mi POM.mxl 文件,并且从一开始它就在控制台上显示以下错误:
Cannot resolve com.sun:tools:0
我总是忽略这一点,因为我的 IDE 中的项目总是编译并运行,而且我从未使用过该依赖项。但是现在我正在尝试在我的 Mac 中使用终端的 maven 支持运行我的项目,并且由于 sun:tools.jar 依赖项,我不允许编译我迄今为止开发的任何工作项目。
我已经阅读了很多关于类似问题的类似主题,它们具有相同的 sun:tools:jar 依赖项,例如:
- Missing artifact com.sun:tools:jar
- Missing Library com.sun.tools.attach
- Could not find artifact com.sun:tools:jar:0
我已经做了所有的事情,但是很多解决方案都是基于在 jdk 安装目录中找到 tools.jar 文件。由于我使用的是 JDK 15,因此此依赖项已被删除:
删除:rt.jar 和 tools.jar
之前存储在lib/rt.jar中的类和资源文件, lib/tools.jar、lib/dt.jar 和其他各种内部 JAR 文件是 现在以更有效的格式存储在特定于实现的文件中 在 lib 目录中。未指定这些文件的格式,并且 如有更改,恕不另行通知。
我附上了我从终端收到的确切错误消息:
----------------------< org.example:YelpExercise >----------------------
[INFO] Building YelpExercise 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.737 s
[INFO] Finished at: 2020-11-04T18:59:47-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project YelpExercise: Could not resolve dependencies for project org.example:YelpExercise:jar:1.0-SNAPSHOT: Could not find artifact com.sun:tools:jar:0 at specified path /Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home/../lib/tools.jar -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
【问题讨论】:
-
tools.jar 如您所见,已在 JDK9 中删除。当您从 pom.xml 中删除依赖项并运行时会发生什么 - 哪些代码无法编译?您可能必须从那里开始
-
这就是问题所在!我没有在我的 pom.xml 中明确添加 tools.jar 依赖项。我认为我的 IDE 这样做是因为它以某种方式指向我的 jdk,因此想要解决这种依赖关系?我对此真的了解不多。我想有一种方法可以排除该特定依赖项,但我不知道如何在我的 pom.xml 文件中声明此显式排除,也没有设置我的 IDE,以便它理解它不应该寻找 tools.jar
-
看起来
tools.jar是您项目中某些 Maven 目标所必需的,但由于它已从 JDK 9+ 中删除,如果在 JDK 9+ 下运行 Maven,您将收到此错误。 -
确实,这种情况一直都在发生。我在一分钟前找到了解决方案并回答了我的问题。看看吧。
标签: java selenium maven intellij-idea tools.jar