1 回答

TA貢獻1827條經(jīng)驗 獲得超8個贊
正如評論中所討論的那樣,這里可能存在一些問題:
模塊定義
本地 jar 和依賴項
基于發(fā)布的模塊化項目,我將創(chuàng)建一個小型演示多模塊化項目來解釋這兩個問題。
Maven 多模塊項目
使用您的 IDE,創(chuàng)建一個 Maven 項目,然后添加兩個模塊,TextInputProgram
例如checker
:
父pom
<groupId>org.openjfx</groupId>
<artifactId>hellofx</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>TextInputProgram</module>
<module>checker</module>
</modules>
<packaging>pom</packaging>
TextInputProgram pom
<parent>
<groupId>org.openjfx</groupId>
<artifactId>hellofx</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>TextInputProgram</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
Module-info.java
module TextInputProgram {
requires selenium.api;
requires selenium.chrome.driver;
exports project to checker;
}
檢查 pom
<parent>
<artifactId>testMods</artifactId>
<groupId>org.openjfx</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>checker</artifactId>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>TextInputProgram</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>sample.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Module-info.java
module checker {
requires javafx.fxml;
requires javafx.controls;
requires TextInputProgram;
opens sample to javafx.fxml;
exports sample;
}
(此時兩個模塊的代碼無關(guān)緊要)。
包括解決方案
現(xiàn)在請注意,您必須將其添加到TextInputProgram模塊描述符中:
exports project to checker;
如果你想讓checker模塊訪問的TextInputProgram包project。
這將解決此錯誤:
包項目在模塊 TextInputProgram 中聲明,不導出它
另請注意,我已將此依賴項包含在checker項目中:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>TextInputProgram</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
即使有兩個模塊,在同一個父模塊下,您也需要包含一個模塊到另一個模塊的依賴關(guān)系。否則這將失?。ㄕ也坏侥K):
requires TextInputProgram;
mvn clean install您可以在模塊中運行TextInputProgram,以安裝org.openjfx:TextInputProgram:1.0-SNAPSHOT在您的本地存儲庫中.m2。
然后您可以運行mvn clean javafx:runintchecker module來運行 GUI 項目。
值得一提的是,將兩個 maven 依賴項與 jar 文件結(jié)合起來并不是一個好主意。如果您最終同時使用兩者,您將收到此錯誤:
模塊“檢查器”從“TextInputProgram”和“TextInputProgram”中讀取“項目”
此消息意味著模塊路徑中有兩個模塊具有完全相同的名稱,一個是 maven 依賴項,另一個是 jar 工件。
為了分發(fā)您的項目和模塊,最好使用 maven 方法,并避免在 lib 文件夾中包含 jar 文件。稍后你的模塊將作為單獨的工件發(fā)布,你不需要修改你的 pom 文件(除了更新版本號)。
添加回答
舉報