jlink未使用自动模块

huangapple go评论68阅读模式
英文:

jlink not using automatic modules

问题

以下是您提供的内容的翻译:

我使用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
...

以下是应用程序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
...

这是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仓库中的模块。是否有更好的解决方法?

谢谢。

英文:

I created a '.exe' file for a JavaFX application on Windows 10 using jpackage. Afterward, by double-clicking on the application's icon, the app did not start. I realized that I mistakenly used this command, which is tailored for none modular application:

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

Now I am trying to use the proper command syntax from Oracle doc for Modular application:

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

Here is my command based on the syntax given by Oracle:

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

However, I am getting an error regarding jlink not using automatic modules: The error message:

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

My application module name in the module-info.class is

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;
}

The application main is org.openjfx.mavenfxedittableview.TableEditApp and the org\openjfx\mavenfxedittableview directory structure is a relative path within the "c:\sample" directory.

The build classes are:

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

09/09/2020  10:32 PM    &lt;DIR&gt;          .
09/09/2020  10:32 PM    &lt;DIR&gt;          ..
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 

<br>
Here is the content of the application jar file:

     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

<br>This is the jar manifest file:

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

Finally, I found out about this Maven plugin ModiTect:

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

, which embeds a descriptor into the jar file of an automatic module, however that would be extremely tedious and time-consuming since the culprit automatic module is not even in my module descriptor. This implies that I might have to go through the .m2 repository and convert them one by one. Are there better work arounds?

Thanks

答案1

得分: 1

你可能想要参考这个教程:https://github.com/dlemmermann/JPackageScriptFX。它同样使用了 jpackage 和 jlink,但以一种适用于非模块化项目的方式进行。你无法直接使用 jlink,因为它不支持自动模块,但通过完全不使用模块化系统,可以避免这个问题。

英文:

You might want to follow this tutorial: https://github.com/dlemmermann/JPackageScriptFX It also uses jpackage and jlink but in a way that makes it usable for non-modular projects. You can't use jlink directly because it does not support automatic modules but this problem can be avoided by just not using the module system at all.

huangapple
  • 本文由 发表于 2020年9月11日 03:01:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63836130.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定