错误:自动模块无法与 jlink 一起使用: - Maven 与 JavaFX

2023-11-22

我通过 Maven 存储库选择了 Apache Commons IO、JSerialComm 和 Ini4J 库。

但是当我尝试通过创建图像时mvn javafx:jlink我收到此错误:

[INFO] --- javafx-maven-plugin:0.0.2:jlink (default-cli) @ JUSBPlotter ---
[WARNING] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!
Error: automatic module cannot be used with jlink: ini4j from file:///root/.m2/repository/org/ini4j/ini4j/0.5.4/ini4j-0.5.4.jar
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
    at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:447)

我似乎与此有关:

Error: automatic module cannot be used with jlink:

我的模块文件如下所示:

module org.openjfx.JUSBPlotter {
    requires javafx.controls;
    requires javafx.fxml;
    requires com.fazecast.jSerialComm;
    requires ini4j;
    requires org.apache.commons.io;

    opens org.openjfx.JUSBPlotter to javafx.fxml;
    exports org.openjfx.JUSBPlotter;
}

我的 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.openjfx</groupId>
    <artifactId>JUSBPlotter</artifactId>
    <version>0.0.1-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>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>com.fazecast</groupId>
            <artifactId>jSerialComm</artifactId>
            <version>2.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.ini4j</groupId>
            <artifactId>ini4j</artifactId>
            <version>0.5.4</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.2</version>
                <configuration>
                    <stripDebug>true</stripDebug>
                    <compress>2</compress>
                    <noHeaderFiles>true</noHeaderFiles>
                    <noManPages>true</noManPages>
                    <launcher>JUSBPlotter</launcher>
                    <jlinkImageName>JUSBPlotter</jlinkImageName>
                    <jlinkZipName>JUSBPlotterZip</jlinkZipName>
                    <mainClass>org.openjfx.JUSBPlotter.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

那么 Apache Commons IO、JSerialComm 和 Ini4J 对于 Maven 和 Jlink 来说是否太旧了?

我应该如何解决这个问题? 我正在使用 Eclipse IDE 和 OpenJDK 11。


The jlink要求所有依赖项都是模块化的。生成后,它会生成一个包含所需模块的自定义 JRE 映像。这ini4j似乎是非模块化的。 对于非模块化依赖项,您可以在获取未使用非模块化依赖项生成的自定义 JRE 后使用旧的类路径方法。

简而言之,运行 jlink 排除非模块,然后将非模块的 jar 文件添加到生成的 JRE 映像中。模块方法和类路径方法可以通过这种方式组合。

稍微摆弄 Maven 插件应该会自动完成此操作。

示例ini4j

  • 为了方便起见,定义一些属性。

pom.xml

<properties>
    <jlink-image-name>JUSBPlotter</jlink-image-name>
    <ini4j-jar-name>ini4j.jar</ini4j-jar-name>
</properties>
  1. Disable ini4j from module-info.java(应该在开发时启用,只有在要打包项目时才这样做)
module org.openjfx.JUSBPlotter {
    requires javafx.controls;
    requires javafx.fxml;
    requires com.fazecast.jSerialComm;
    //requires ini4j;
    requires org.apache.commons.io;

    opens org.openjfx.JUSBPlotter to javafx.fxml;
    exports org.openjfx.JUSBPlotter;
}
  1. 配置maven-dependency-plugin复制 jar 文件ini4j进入lib/jlink 图像中的文件夹。
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <artifactItems>
            <!-- Copy ini4j jar into the jlink image -->
            <artifactItem>
              <groupId>org.ini4j</groupId>
              <artifactId>ini4j</artifactId>
              <version>0.5.4</version>
              <type>jar</type>
              <destFileName>${ini4j-jar-name}</destFileName>
            </artifactItem>
          </artifactItems>
          <!-- Set output directory to lib folder in jlink image -->
          <outputDirectory>${project.build.directory}/${jlink-image-name}/lib</outputDirectory>
          <overWriteReleases>true</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
</plugin>
  1. 配置jlink中的启动器选项javafx-maven-plugin为了添加非模块化的jar文件ini4j到类路径。
<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.8</version>
    <configuration>
        <stripDebug>true</stripDebug>
        <compress>2</compress>
        <noHeaderFiles>true</noHeaderFiles>
        <noManPages>true</noManPages>
        <launcher>JUSBPlotter</launcher>
        <jlinkImageName>JUSBPlotter</jlinkImageName>
        <mainClass>org.openjfx.JUSBPlotter.Main</mainClass>
        <!-- ini4j jar file will be copied to the {image-folder}/lib/ folder. The launcher script should have this option to add it to the classpath -->
        <options>-cp ../lib/${init4j-jar-name}</options>
    </configuration>
</plugin>

Run:

  • mvn clean javafx:jlink
  • mvn package
  • cd target/JUSBPlotter/bin
  • ./JUSBPlotter

maven-dependeny-plugin运行时会复制 jar 文件mvn package。但 jlink 镜像必须已经生成。所以运行mvn javafx:jlink第一的。然后运行mvn package.

Refer here看看我是如何申请的sqlite-jdbc在我的项目中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误:自动模块无法与 jlink 一起使用: - Maven 与 JavaFX 的相关文章

随机推荐

  • 如何计算某个日期范围内有多少晚?

    我需要根据入住和退房日期计算住宿天数 入住酒店 最好的方法是什么 即 如果我有 Checkin 12 11 2009 15 00 hs Checkout 14 11 2009 12 00 hs Doing Checkout Checkin
  • 如何使 ON DELETE CASCADE 在 sqlite 3.7.4 中工作?

    我检查了几次功能列表 似乎级联应该可以工作 当我执行这个 python 脚本时 usr bin env python3 import sqlite3 print sqlite3 sqlite version con sqlite3 conn
  • 是否可以检测 ACTION_SEND Intent 是否成功?

    我有一个简单的 Android 应用程序 其代码如下 来自安卓文档 Intent sendIntent new Intent sendIntent setAction Intent ACTION SEND sendIntent putExt
  • Dockerfile 的优点

    我们可以创建 Docker 映像并将它们全部推送到 Hub 而无需 Dockerfile Dockerfile 为什么有用 它有什么优点呢 Dockerfile 的创建是一个非常耗时的过程 并且只能由人来完成 我想知道基于基础镜像的提交镜像
  • msysgit 的麻烦

    所以我似乎在设置 msysgit 时遇到了一些实际问题 我可以使用 putty 连接到我的 SSH 目录 ssh 用户 主机 端口 我有正确的钥匙 我也可以使用 plink 通过 plink P PORT user host i path
  • jVectorMap 渲染太小

    我的 jVectorMap 没有采用我在包含的 div 上提供的新高度 并且仅以默认 高度 54px 进行渲染 这是我的 script js 文件中的 document ready 函数 team map usa vectorMap map
  • MS Project 甘特图控件在 C# 中的使用

    有人用过 C 中的 MS Project 甘特图控件吗 如果是 您能分享一些与此相关的资源吗 您还可以检查甘特图库对于 WPF 或 Windows 窗体 它们不需要在客户端计算机上安装 Microsoft Project 但为项目和相关甘特
  • 中继器内的复选框,如何在检查更改功能中获取命令名称值

    您好 我的 asp net listview 项目模板中有上面的 html 标记 td td
  • Go 中什么时候应该使用 new ?

    在原始语言结构中使用似乎毫无意义 因为您无法指定任何类型的值 func main y new float fmt Printf Len d len y gt Len 0 对于结构来说 它使bit更有道理 但是说起来有什么区别y new my
  • 如何使用react-router使用私有路由?

    我想使用身份验证来创建安全路由 我已经在 App jsx 文件中定义了路由 我使用 Route 来定义要渲染的组件 在 App jsx 中
  • 如何删除所有重复项,以便数据框中不留下任何重复项?

    有一个类似的问题对于 PHP 但我正在使用 R 并且无法将解决方案转化为我的问题 我有一个包含 10 行和 50 列的数据框 其中一些行完全相同 如果我在它上面使用 unique 我会得到一行 比方说 类型 但我真正想要的是只得到那些只出现
  • ELF 标头魔法 - 为什么将 0x7F 放入其中?

    我读过的关于 ELF header magic 的每一个资源都指出它包含 ASCII 编码的 ELF 然后简短地提到 0x7F 被添加到它前面而没有解释 0x7F有什么原因吗 是为了避免与现有格式发生冲突吗 是否符合现有标准 用于检测有关磁
  • Node.js 中类似“生成线程”的行为

    我想向一个小型 Web 应用程序添加一些管理实用程序 例如 备份数据库 用户单击按钮 HTTP 响应将立即返回 尽管可能长时间运行的进程已在后台启动 在 Java 中 这可能通过生成一个独立线程来实现 在 Scala 中则通过使用 Acto
  • 在WM6上查找存储卡路径

    有没有一种简单的方法可以在 Windows Mobile 设备上找到存储卡的路径 当有存储卡和蓝牙ftp连接时 挂载点通常是 Storage Card 但可以本地化为其他语言或由 OEM 修改 某些设备使用 SD Card 或其他挂载点 并
  • 如何在 Haskell 中处理无限的 IO 对象列表?

    我正在编写一个从文件列表中读取的程序 每个文件要么包含到下一个文件的链接 要么标记它是链的末尾 作为 Haskell 的新手 处理这个问题的惯用方法似乎是为此目的提供一个可能文件的惰性列表 我有 getFirstFile String gt
  • WPF - 如何强制命令通过其 CommandBindings 重新评估“CanExecute”

    我有一个Menu其中每个MenuItem在层次结构中有其Command属性设置为RoutedCommand我已经定义了 相关的CommandBinding提供评估的回调CanExecute它控制每个的启用状态MenuItem This al
  • 闭包如何捕获之前调用的值?

    typealias IntMaker Void gt Int func makeCounter gt IntMaker var n 0 Line A func adder gt Integer n n 1 return n return a
  • 禁用 JavaDocs 的注释

    是否有一个注释来声明某个方法即使是公共的也不会包含在JavaDocs中 就像是 nojavadocs public void foo 附 我理解这里关于 API 的要点 但这些方法只是 不受支持 它们可以工作 并且必须公开才能从其他包访问
  • C++ 中的多线程图像处理

    我正在开发一个处理不同尺寸图像的程序 许多这些操作从输入读取像素数据并写入单独的输出 例如模糊 这是在每个像素的基础上完成的 此类图像映射对 CPU 的压力很大 我想使用多线程来加快速度 我该怎么做 我正在考虑为每行像素创建一个线程 我有几
  • 错误:自动模块无法与 jlink 一起使用: - Maven 与 JavaFX

    我通过 Maven 存储库选择了 Apache Commons IO JSerialComm 和 Ini4J 库 但是当我尝试通过创建图像时mvn javafx jlink我收到此错误 INFO javafx maven plugin 0