[英]Compilation Error with Maven on Intellij: Module not found: processed.jcommander
我正在使用 selenium 和 javaFX 開發一些小程序。當我分別在 selenium 項目和 JavaFX 項目上嘗試我的代碼時,一切都很順利。 當我將代碼放在一起並將所有依賴項導入到 maven 並嘗試運行時,它一直顯示此錯誤:
[ERROR] COMPILATION ERROR :[INFO] -------------------------------------------------------------[ERROR] module not found: processed.jcommander[ERROR] module not found: processed.async.http.client
我不知道那些模塊是什么,它們不是依賴項,也沒有在代碼中使用。 這些模塊是什么以及為什么會出現編譯錯誤?
這是我的 POM.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>DedoDoDida</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.7.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.projectlombok</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!-- <version>1.18.6</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.google.code.gson</groupId>-->
<!-- <artifactId>gson</artifactId>-->
<!-- <version>2.10</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>20-ea+11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>20-ea+11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>19</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>org.example.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我已經嘗試在 inte.net 上搜索,我已經在這個問題上停留了 2 天,我放棄了這個項目,但我決定嘗試 stackoverflow。 可能是一些我無法解決的容易解決的事情。
發生這種情況是因為用於您正在使用的 Selenium 軟件4.7.1
版本的 Java 平台模塊定義(對我而言)似乎已損壞。
我正在使用您在應用程序中更新的 pom.xml:
- javafx-maven-plugin 的當前版本是 0.0.8。
- JavaFX當前的非搶先體驗(版本中沒有-ea)是19。
以及selenium 文檔中的 hello world 程序。
package dev.selenium.hello;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class HelloSelenium {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.get("https://selenium.dev");
driver.quit();
}
}
據我所知(我真的找不到這方面的文檔),所以可能目前甚至不支持,要在模塊化應用程序中使用 Selenium,您需要在module-info.java
。 這些是我在嘗試編譯上述程序時由我的 IDE 建議的。
requires org.seleniumhq.selenium.api;
requires org.seleniumhq.selenium.chrome_driver;
完成后,后續的mvn:compile
會給出問題中的錯誤:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] module not found: processed.jcommander
[ERROR] module not found: processed.async.http.client
這些模塊不在 selenium 的傳遞依賴項中,因此 selenium 模塊已損壞。 工件有maven依賴,所以你可以在Maven引入的庫依賴中看到jcommander和async-http-client jar,但是這些jar不提供任何模塊信息,所以它們的模塊名稱應該來自jar文件名稱為“自動模塊”。 這意味着它們將從module-info.java
中引用為:
requires jcommander;
requires async.http.client;
但是它們沒有使用這些名稱進行引用。
selenium-chrome-driver jar 有:
module org.seleniumhq.selenium.chrome_driver {
...
requires org.seleniumhq.selenium.remote_driver;
...
}
selenium-remote-driver jar 有:
module org.seleniumhq.selenium.remote_driver {
...
requires processed.async.http.client;
requires processed.jcommander;
...
}
所以這些是錯誤的名稱,經過processed.
前綴不存在,因此如果您定義了module-info.java
,那么簡單的HelloSelenium
應用程序將無法使用。
我現在可以建議的唯一解決方法是通過不定義module-info.java
使您的應用程序成為非模塊化的(即刪除module-info.java
文件,如果您的項目中有一個文件。)。
但是,由於 JavaFX 需要位於模塊路徑上,因此您還需要:
我還建議為 selenium 項目提交錯誤,以修復 selenium-remote-driver jar 中損壞的模塊定義。
由於其他答案沒有提到這一點,我想把它放在這里 4.6.0 版本工作正常並且沒有給出類似的錯誤。 如果您不需要從 4.7.x 引入的特定增強功能/錯誤修復,您可以使用 4.6.0。 我之前也使用過 4.7.2,但回滾到 4.6.0,它工作得很好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.