我目前正在開發一個模塊化的 JavaFX 應用程式,我正在使用 maven 編譯/部署它。
我的應用程式的依賴項之一是 JBibTex,它沒有module-info檔案,因此用作自動模塊。為了讓我javafx:jlink的作業(因為javafx:jlink不能在自動模塊上作業),我必須將 JBibTex 轉換為顯式模塊。我為此使用了 Maven 的ModiTect插件。
我使用 ModiTectmodule-info為 JBibTex 庫生成檔案,并將其添加到 JBibTex 的 jar 檔案中(我用于moditect:add-module-infos那個)。
現在的問題是javafx:jlink使用位于我的“.m2”檔案夾中的 JBibTex.jar 檔案(maven 自動下載所有專案的依賴項)。位于我的 .m2 檔案夾中的 JBibTex.jar 檔案不是我添加模塊資訊檔案的檔案。
所以我仍然收到錯誤:
錯誤:自動模塊不能與 jlink 一起使用:jbibtex
我通過使用 ModiTect 生成的顯式 JBibtex 模塊target/modules由我的 ModiTect 插件配置自動放入。
我怎樣才能javafx:jlink使用target/modules/JBibTex.jar包含 module-info.class 檔案而不是我的 .m2 檔案夾的 JBibTex.jar 的檔案?
這是我的 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxx</groupId>
<artifactId>BRM</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>BRM</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<mainClass>xxx.App</mainClass>
<moduleName>xxx.brm</moduleName>
<javafx.version>17.0.1</javafx.version>
<javafx.maven.plugin.version>0.0.8</javafx.maven.plugin.version>
</properties>
<dependencies>
<!-- javafx dependencies -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jbibtex/jbibtex -->
<dependency>
<groupId>org.jbibtex</groupId>
<artifactId>jbibtex</artifactId>
<version>1.0.17</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>configs</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>${javafx.maven.plugin.version}</version>
<configuration>
<mainClass>${mainClass}</mainClass>
<launcher>launcher</launcher>
<jlinkImageName>BRM</jlinkImageName>
</configuration>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.RC2</version>
<executions>
<execution>
<id>add-module-infos</id>
<phase>generate-resources</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<overwriteExistingFiles>true</overwriteExistingFiles>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<modules>
<module>
<artifact>
<groupId>org.jbibtex</groupId>
<artifactId>jbibtex</artifactId>
<version>1.0.17</version>
</artifact>
<moduleInfoSource>
module jbibtex
{
exports org.jbibtex;
}
</moduleInfoSource>
</module>
</modules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
uj5u.com熱心網友回復:
具體回答你的問題:
如何指定使用的模塊路徑?
您可以從命令列而不是通過 Maven 運行 jlink。
這樣你就可以指定任何你想要的模塊路徑。
從jlink的手冊頁:
jlink [options] --module-path modulepath --add-modules module [, module...]模塊路徑
jlink 工具發現可觀察模塊的路徑。這些模塊可以是模塊化 JAR 檔案、JMOD 檔案或分解模塊。
模塊
要添加到運行時映像的模塊的名稱。jlink 工具添加了這些模塊及其傳遞依賴項。
如果您希望繼續使用 openjfx maven plugin jlink 命令,您可以這樣做。
配置由 maven 插件傳遞給 jlink 的模塊路徑的代碼在 git 中。
if (modulepathElements != null && !modulepathElements.isEmpty()) {
commandArguments.add(" --module-path");
String modulePath = StringUtils.join(modulepathElements.iterator(), File.pathSeparator);
if (jmodsPath != null && ! jmodsPath.isEmpty()) {
getLog().debug("Including jmods from local path: " jmodsPath);
modulePath = jmodsPath File.pathSeparator modulePath;
}
commandArguments.add(modulePath);
commandArguments.add(" --add-modules");
if (moduleDescriptor != null) {
commandArguments.add(" " moduleDescriptor.name());
} else {
throw new MojoExecutionException("jlink requires a module descriptor");
}
}
這是基于javafx:jlink 選項:
jmodsPath:當使用本地JavaFX SDK時,設定本地JavaFX jmods的路徑
因此,如果您將模塊放在該選項指定的路徑上,則應該可以找到它。
這里有一些其他選項。
使用 jpackage 將您的應用程式打包為非模塊化應用程式
我認為 mipa 建議使用 JPackageScriptFX 可能是最好的方法:
- github.com/dlemmermann/JPackageScriptFX
從二進制檔案創建一個新的 jar
- 解壓 JBibTex.jar。
- 將編譯后的模塊資訊添加到 unjared 目錄中。
- 創建一個新的 jar,例如 JBibTexModule.jar。
- 通過 mvn install 命令將其安裝到您的 maven 存盤庫。
- 添加對 JBibTexModule 而不是 JBibTex 的 maven 依賴。
- 將任何需要的陳述句添加到您的主應用程式模塊資訊檔案以使用該庫。
然后,我相信你已經完成了,它會構建、鏈接和運行。
從源創建一個新的 jar
jbibtex 庫也在github 中,因此您可以在專案上創建問題或拉取請求以要求對其進行模塊化。
此外,您可以:
- 克隆存盤庫。
- 添加模塊資訊.java。
- 構建 jar 檔案。
- 將其本地安裝在本地 Maven 存盤庫中。
- 然后取決于您創建的本地版本。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/378561.html
上一篇:java.nio.file.InvalidPathException:Illegalchar<">atindex0:"C:\ProgramFiles\Git\bi
