无法解析Maven项目中的com.sun:tools:0



我最近一直在研究测试自动化。

我现在已经熟悉了一些工具、框架、依赖项等,比如Selenium、JUNits、TestNG,这些工具可以帮助我作为QA工程师管理日常工作。

我经常使用Selenium和TestNG来构建我的解决方案,以及运行在最新JDK版本(JDK-15.0.1(上的IntelliJ IDEA,该版本可在运行macOsCatalina 10.15.7的Mac上使用

我已经为我的项目配置了mi POM.mxl文件,从一开始它就在控制台上显示了以下错误:

Cannot resolve com.sun:tools:0

我总是忽略这一点,因为我的IDE中的项目总是编译&运行,因为我从未使用过这种依赖关系。但现在我正试图在Mac上的终端上使用maven支持来运行我的项目,由于对sun:tools.jar的依赖,我不允许编译迄今为止开发的任何工作项目。

我读过很多关于相同sun:tools:jar依赖关系中类似问题的类似线程:

  • 缺少工件com.sun:tools:jar
  • 缺少库com.sun.tools.attach
  • 找不到工件com.sun:tools:jar:0

我已经做了所有的工作,但许多解决方案都是基于在jdk安装目录中找到tools.jar文件。由于我使用的是JDK15,这个依赖项已经被删除:

删除: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

好吧,经过数小时甚至数天的研究,我找到了解决方案:

对于JDK 9及以上版本,在定义pom.xml时,无论何时使用包含子依赖项的依赖项,都必须排除该子依赖项。在我的案例中,cobertura依赖项包括sun.com:tools.

我在pom.xml文件中编辑的内容:

<!-- https://mvnrepository.com/artifact/net.sourceforge.cobertura/cobertura -->
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>2.1.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>
</dependency>

对于一些maven依赖项来说,这似乎仍然是一个悬而未决的问题。检查:issues1或issues2或谷歌搜索:<dependency_you_are_using>sun工具了解更多信息。

相关内容

最新更新