第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java 11 包在不導出它的模塊中聲明

Java 11 包在不導出它的模塊中聲明

慕田峪9158850 2023-05-24 16:29:42
我創(chuàng)建了兩個模塊化程序。一個是 JavaFX 模塊化項目,其中包含module-info.java:module checker {    requires javafx.fxml;    requires javafx.controls;    requires TextInputProgram; // Btw, IDEA shows me here "Ambiguous module reference"    exports sample;    opens sample;}另一個包含module-info.java如下內(nèi)容的 Maven 項目:module TextInputProgram {    requires selenium.api;    requires selenium.chrome.driver;}因此,我將模塊化 Maven 項目作為外部 jar 添加到 JavaFX 中(通過 libs 中的項目結(jié)構(gòu)和通過我指定的 jar 在模塊信息中requires)。我還添加了包含用于編譯的外部 jar 的變量(除了PATH_TO_FX和PATH_TO_FX_MODS):set EXTERNAL_JAR="...\out\artifacts\TextInputProgram_jar"但是當我試圖通過命令編譯項目時:dir /s /b src\*.java > sources.txt & javac --module-path %EXTERNAL_JAR%;%PATH_TO_FX% -d mods/checker @sources.txt & del sources.txt按照本教程我從 JavaFX 項目類中得到錯誤:\src\sample\Controller.java:9: error: package project is not visibleimport project.SeleniumProgram;       ^  (package project is declared in module TextInputProgram, which does not export it)1 errorPackage is declared in module which does not export itimport project.SeleniumProgram我在 JavaFX 項目中導入以使用來自外部 jar 的類。更新:如果我exports project;在 maven 項目的 module-info.java 中添加,那么我會在 JavaFX module-info.java 中看到錯誤:如果我刪除,requires TextInputProgram;那么導入時會出現(xiàn)另一個錯誤我在這里錯過了什么嗎?我正在嘗試獲取這兩個程序的可執(zhí)行 Jar。
查看完整描述

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 文件(除了更新版本號)。


查看完整回答
反對 回復 2023-05-24
  • 1 回答
  • 0 關(guān)注
  • 228 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號