簡體   English   中英

無法在 Maven 項目中解析 com.sun:tools:0?

[英]Cannot resolve com.sun:tools:0 in Maven Project?

我最近一直在研究自動化測試。

我現在熟悉了幾個工具、框架、依賴項等,比如 Selenium、JUNits、TestNG,它們可以幫助我管理我作為 QA 工程師的日常工作。

我經常使用 Selenium 和 TestNG 來構建我的解決方案,以及運行在最新 JDK 版本 (jdk-15.0.1)上的IntelliJ IDEA,可在運行 macOs Catalina Version 10.15.7Mac 上使用

我已經為我的項目配置了 mi POM.mxl 文件,從一開始它就在控制台上顯示以下錯誤:

Cannot resolve com.sun:tools:0

我總是忽略這一點,因為我的 IDE 中的項目總是編譯和運行,並且因為我從未使用過該依賴項。 但是現在我試圖在我的 Mac 的終端中使用 maven 支持運行我的項目,並且由於 sun:tools.jar 依賴項,我不允許編譯到目前為止我開發的任何工作項目。

我已經閱讀了很多關於相同 sun:tools:jar 依賴項的類似問題的類似線程,例如:

我什么都做了,但是很多解決方案都是基於在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

好的,經過數小時甚至數天的研究,我找到了解決方案:

對於 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 依賴項,這似乎仍然是一個懸而未決的問題。 檢查: issues1issues2或谷歌搜索: <dependency_you_are_using> sun tools了解更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM