简体   繁体   English

如何从 a.jar 成功生成 working.exe,包括 jre 和必要的依赖项?

[英]How to successfully generate a working .exe from a .jar including a jre and the necessary dependencies?

0 What I have so far: 0 我到目前为止所拥有的:

So I build an application with Java 17 using JavaFX for the UI Stuff.因此,我使用 JavaFX 为 UI Stuff 构建了一个带有 Java 17 的应用程序。 After sveral attempts I finally generated a.jar-File that runs the programm with the following command:经过几次尝试,我终于生成了一个.jar-File,它使用以下命令运行程序:

java --module-path ".\jre" --add-modules java.base --module-path
".\lib\lib" --add-modules javafx.controls,javafx.fxml,javafx.graphics
-jar .\bin\Memorygame.jar --main-class java/spotted/memorygame/MemoryGame.java

Regarding the structure:关于结构:

 |
 |-bin
     |- Memory.jar
 |
 |-jre
     |-here lies the jdk it should use 
 |
 |-lib
     |-here are the files for JavaFX

I had serveral failed attempts to generate a working exe with an own runtime environment.我曾多次尝试使用自己的运行时环境生成工作 exe,但都失败了。

1 Attempt Launch4j 1 次尝试 Launch4j

I somehow managed to pack the jre into the final exe but running that resulted in a我以某种方式设法将 jre 打包到最终的 exe 中,但运行结果是

java.lang.noclassdeffounderror: javafx/application/application

So I tried to give the module info to where the JavaFX lies and what modules I want to use in the JVM Field in Launch4j.因此,我尝试将模块信息提供给 JavaFX 所在的位置以及我想在 Launch4j 的 JVM 字段中使用哪些模块。 I still got the same Problem.我仍然遇到同样的问题。

2 Attempt JPackage without a main-class 2 尝试没有主类的 JPackage

I read that jpackage works sometimes better than Launch4j, so i try it next.我读到 jpackage 有时比 Launch4j 工作得更好,所以我接下来尝试一下。 Building the exe (or msi I tried both with the same result) works completly fine.构建 exe(或我尝试过的 msi,结果相同)完全可以正常工作。

jpackage  -t exe --name "Memorygame" --app-version 1.0.0 --input ".\bin" --dest ".\bin" 
--main-jar "Memorygame.jar" --module-path ".\jre" --add-modules java.se 
--module-path ".\lib\lib" --add-modules javafx.controls,javafx.graphics,javafx.fxml

I get an installer that works, when I now try and run the.exe that was installed I get a我得到了一个可以工作的安装程序,当我现在尝试运行已安装的.exe 时,我得到了一个

Failed to load JVM and afterwards a Child process exited with code 1 Failed to load JVM ,随后Child process exited with code 1

I start my next and up to this point last one:我开始我的下一个,直到这一点最后一个:

3 Attempt jpackage with main-class 3 尝试使用主类的 jpackage

I use the exact same comand as in the scend one but i add a main-class option:我使用与 scend 完全相同的命令,但我添加了一个主类选项:

jpackage  -t exe --name "Memorygame" --app-version 1.2.0 --input ".\bin" --dest ".\bin" 
--main-jar "Memorygame.jar" --module-path ".\jre" --add-modules java.se 
--module-path ".\lib\lib" --add-modules javafx.controls,javafx.graphics,javafx.fxml
 --main-class java/spotted/memorygame/MemoryGame.java

(I can actually leave out the java/ -part of the classpath, it still has the same resut.) (我实际上可以省略类路径的 java/ -part,它仍然具有相同的结果。)

Installing and starting this, results only in the Child process exited with code 1安装并启动它,只会导致Child process exited with code 1

My Question now:我现在的问题:

Does someone know, where the mistakes in my attempts lie and maybe has a way to solve them?有人知道我尝试中的错误在哪里,也许有办法解决它们? Or a completly different way to approach the problem?还是以完全不同的方式解决问题?

Just have a look here https://github.com/dlemmermann/JPackageScriptFX and compare your setup with this working one.只需在此处查看https://github.com/dlemmermann/JPackageScriptFX并将您的设置与此工作设置进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM