英文:
Using ModiTect to generate module info and create runtime image
问题
尝试使用 JLink 创建运行时镜像时出现了以下错误:
错误:无法使用 JLink 创建自动模块:graphviz.java
我正在使用以下 库,该库仅包含自动模块。
经过一些搜索,似乎我可以使用 ModiTect 为该库生成 module-info,并创建运行时镜像。
然而,由于我对模块的了解有限,我无法弄清楚。
我想我可能需要一个比我在 ModiTect 的 GitHub 页面上找到的更详细的解释。
我的 modules-info.java 文件:
module elitonlais {
requires javafx.controls;
requires javafx.fxml;
requires graphviz.java;
opens elitonlais to javafx.fxml;
opens elitonlais.controller to javafx.fxml;
opens elitonlais.model to javafx.fxml;
exports elitonlais;
exports elitonlais.controller;
exports elitonlais.model;
}
我的 pom 文件:
<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>elitonlais</groupId>
<artifactId>minafd</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>guru.nidi</groupId>
<artifactId>graphviz-java</artifactId>
<version>0.17.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<!-- 其他插件略 -->
</plugins>
</build>
</project>
完整的项目结构:
https://github.com/EMachad0/MinAFD
英文:
Tried to use JLink to create a runtime image, however:
Error: automatic module cannot be used with JLink: graphviz.java
I'm using the following library which has only automatic modules.
Did some searches, and it seems that I can use ModiTect to generate module-info for the library and create a runtime image.
However, as I am new to modules I couldn't figure it out.
I guess I would need a more in-depth explanation then what I could find on ModiTect's GitHub page.
my modules-info.java:
module elitonlais {
requires javafx.controls;
requires javafx.fxml;
requires graphviz.java;
opens elitonlais to javafx.fxml;
opens elitonlais.controller to javafx.fxml;
opens elitonlais.model to javafx.fxml;
exports elitonlais;
exports elitonlais.controller;
exports elitonlais.model;
}
My pom file:
<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>elitonlais</groupId>
<artifactId>minafd</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>guru.nidi</groupId>
<artifactId>graphviz-java</artifactId>
<version>0.17.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>elitonlais.App</mainClass>
<launcher>launch.sh</launcher>
<compress>2</compress>
<jlinkZipName>MinAFD</jlinkZipName>
<jlinkImageName>MinAFD</jlinkImageName>
<includePathExceptionsInClasspath>true</includePathExceptionsInClasspath>
</configuration>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.Beta2</version>
<executions>
<execution>
<id>create-runtime-image</id>
<phase>package</phase>
<goals>
<goal>create-runtime-image</goal>
</goals>
<configuration>
<modulePath>
<path>${project.build.directory}/modules</path>
</modulePath>
<modules>
<module>module-info.java</module>
<!-- <module>javafx.controls</module>
<module>javafx.graphics</module> -->
</modules>
<launcher>
<name>test33</name>
<module>module-info.java/elitonlais.app</module>
</launcher>
<compression>2</compression>
<stripDebug>true</stripDebug>
<outputDirectory>${project.build.directory}/jlink-image</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The entire project structure:
https://github.com/EMachad0/MinAFD
答案1
得分: 1
你应该能够按照链接中的文档 将模块描述符添加到现有的 JAR 文件中 进行添加。
将以下内容作为额外的 <execution>
步骤添加到现有的 pom.xml
中,用于 ModiTect,应该可以工作:
<executions>
<execution>
<!-- 这里放置你现有的代码 -->
</execution>
<execution>
<id>add-module-infos</id>
<phase>generate-resources</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<modules>
<module>
<artifact>
<groupId>guru.nidi</groupId>
<artifactId>graphviz-java</artifactId>
<version>0.17.0</version>
</artifact>
<moduleInfo>
<name>guru.nidi.graphviz</name>
<exports>
*;
</exports>
<!-- 可能还有其他微调 -->
</moduleInfo>
</module>
<module>
...
</module>
</modules>
</configuration>
</execution>
</executions>
还要注意,该项目已经指定了一个自动模块名为 guru.nidi.graphviz
,因此您需要将自己的 module-info
更改为需要该模块,而不是自动生成的 graphviz.java
。
英文:
You should be able to add it following the documentation at the link Adding module descriptors to existing JAR files.
Adding the following to your existing pom.xml
as an additional <execution>
step for ModiTect should work:
<executions>
<execution>
<!-- your existing code here -->
</execution>
<execution>
<id>add-module-infos</id>
<phase>generate-resources</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<modules>
<module>
<artifact>
<groupId>guru.nidi</groupId>
<artifactId>graphviz-java</artifactId>
<version>0.17.0</version>
</artifact>
<!-- only use one of either moduleInfo or moduleInfoSource -->
<moduleInfo>
<name>guru.nidi.graphviz</name>
<exports>
*;
</exports>
<!-- possibly other fine-tuning -->
</moduleInfo>
<!-- only use one of either moduleInfo or moduleInfoSource -->
<moduleInfoSource>
module guru.nidi.graphviz {
requires ...;
exports ...;
provides ...
with ...;
}
</moduleInfoSource>
<!-- or use moduleInfoFile instead of the above -->
</module>
<module>
...
</module>
</modules>
</configuration>
</execution>
</executions>
Note also that the project has specified an automatic module name of guru.nidi.graphviz
so you'll need to change your own module-info
to require that, rather than the auto-derived graphviz.java
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论