微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jlink不使用自动模块

如何解决jlink不使用自动模块

我使用jpackage在Windows 10上为JavaFX应用程序创建了一个'.exe'文件。之后,通过双击应用程序的图标,该应用程序无法启动。我意识到我错误地使用了此命令,该命令是为非模块化应用程序量身定制的:

jpackage --input app-directory --main-jar jar-file [--main-class main-class]

现在,我正在尝试使用Oracle文档中适用于模块化应用程序的正确命令语法:

jpackage --module-path module-path --module main-module[/class]

这是我基于Oracle给出的语法的命令:

jpackage -p "%JAVAFX_HOME%\lib;%M2_REPO%;org\openjfx\mavenfxedittableview\mavenfxedittableview.jar" --module "org.openjfx.mavenfxedittableview/org.openjfx.mavenfxedittableview.TableEditApp"

但是,我收到有关不使用自动模块的jlink的错误错误消息:

WARNING: Using incubator modules: jdk.incubator.jpackage
jlink Failed with: Error: automatic module cannot be used with jlink: javafx.swt from file:///C:/Program%20Files/java/jFX/javafx-sdk-14.0.2.1/lib/javafx-swt.jar

module-info.class中我的应用程序模块名称

module org.openjfx.mavenfxedittableview {
requires javafx.controls;
requires javafx.fxml;
requires java.base;
requires java.prefs;
requires transitive java.xml.bind;

opens org.openjfx.mavenfxedittableview to java.xml.bind,javafx.fxml;
exports org.openjfx.mavenfxedittableview;
    
}

应用程序主要是org.openjfx.mavenfxedittableview.TableEditApp,而org \ openjfx \ mavenfxedittableview目录结构是“ c:\ sample”目录中的相对路径。

构建类为:

 Directory of C:\Sample\org\openjfx\mavenfxedittableview

09/09/2020  10:32 PM    <DIR>          .
09/09/2020  10:32 PM    <DIR>          ..
09/09/2020  08:36 PM             2,502 addressBookData.xml
09/09/2020  08:36 PM             9,562 Address_Book.png
09/09/2020  08:36 PM               859 birthdaystatistic.fxml
09/09/2020  08:36 PM             3,274 BirthdaystatisticController.class
09/09/2020  08:36 PM             3,224 DarkTheme.css
09/09/2020  08:36 PM             2,072 DateUtil.class
09/09/2020  08:36 PM             1,214 LocalDateAdapter.class
09/09/2020  10:32 PM            34,004 mavenfxedittableview.jar
09/09/2020  08:36 PM             3,523 Person.class
09/09/2020  08:36 PM             4,535 personeditdialog.fxml
09/09/2020  08:36 PM             5,128 PersoneditdialogController.class
09/09/2020  08:36 PM             1,029 PersonListWrapper.class
09/09/2020  08:36 PM             6,412 personoverview.fxml
09/09/2020  08:36 PM             1,904 rootlayout.fxml
09/09/2020  08:36 PM             4,490 RootlayoutController.class
09/09/2020  08:36 PM             9,060 TableEditApp.class
09/09/2020  08:36 PM             6,812 TableVieweditController.class
              17 File(s)         99,604 bytes
               2 Dir(s)  56,574,193,664 bytes free 

这是应用程序jar文件内容
     0 Wed Sep 09 22:32:14 IRDT 2020 meta-inf/
   125 Wed Sep 09 22:32:14 IRDT 2020 meta-inf/MANIFEST.MF
  2502 Wed Sep 09 20:36:28 IRDT 2020 org/openjfx/mavenfxedittableview/addressBookData.xml
  9562 Wed Sep 09 20:36:28 IRDT 2020 org/openjfx/mavenfxedittableview/Address_Book.png
   859 Wed Sep 09 20:36:28 IRDT 2020 org/openjfx/mavenfxedittableview/birthdaystatistic.fxml
  3274 Wed Sep 09 20:36:30 IRDT 2020 org/openjfx/mavenfxedittableview/BirthdaystatisticController.class
  3224 Wed Sep 09 20:36:28 IRDT 2020 org/openjfx/mavenfxedittableview/DarkTheme.css
  2072 Wed Sep 09 20:36:30 IRDT 2020 org/openjfx/mavenfxedittableview/DateUtil.class
  1214 Wed Sep 09 20:36:30 IRDT 2020 org/openjfx/mavenfxedittableview/LocalDateAdapter.class
  3523 Wed Sep 09 20:36:30 IRDT 2020 org/openjfx/mavenfxedittableview/Person.class
  4535 Wed Sep 09 20:36:28 IRDT 2020 org/openjfx/mavenfxedittableview/personeditdialog.fxml
  5128 Wed Sep 09 20:36:30 IRDT 2020 org/openjfx/mavenfxedittableview/PersoneditdialogController.class
  1029 Wed Sep 09 20:36:30 IRDT 2020 org/openjfx/mavenfxedittableview/PersonListWrapper.class
  6412 Wed Sep 09 20:36:28 IRDT 2020 org/openjfx/mavenfxedittableview/personoverview.fxml
  1904 Wed Sep 09 20:36:28 IRDT 2020 org/openjfx/mavenfxedittableview/rootlayout.fxml
  4490 Wed Sep 09 20:36:30 IRDT 2020 org/openjfx/mavenfxedittableview/RootlayoutController.class
  9060 Wed Sep 09 20:36:30 IRDT 2020 org/openjfx/mavenfxedittableview/TableEditApp.class
  6812 Wed Sep 09 20:36:30 IRDT 2020 org/openjfx/mavenfxedittableview/TableVieweditController.class
   349 Wed Sep 09 22:32:14 IRDT 2020 module-info.class


这是jar清单文件

Manifest-Version: 1.0
Main-Class: org.openjfx.mavenfxedittableview.TableEditApp
Created-By: 14.0.2 (Oracle Corporation)

最后,我发现了这个Maven插件ModiTect:

https://www.youtube.com/watch?v=BhuOSGrNBek

,它将描述符嵌入到自动模块的jar文件中,但是,这是非常繁琐且耗时的,因为罪魁祸首自动模块甚至不在我的模块描述符中。这意味着我可能必须浏览.m2存储库,并将它们一个一个地转换。有更好的解决方法吗?

谢谢

解决方法

您可能希望遵循本教程:https://github.com/dlemmermann/JPackageScriptFX它还使用jpackage和jlink,但其使用方式使其可用于非模块化项目。您不能直接使用jlink,因为它不支持自动模块,但是可以通过完全不使用模块系统来避免此问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。