简体   繁体   English

我用 Launch4j 创建的 .exe 没有运行

[英]The .exe I created with Launch4j doesn't run

I was able to successfully create a.exe file from an executable jar. From Launch4j I can test the wrapper, and the output on the log is what I expect.我能够从可执行文件 jar 成功创建 a.exe 文件。我可以从 Launch4j 测试包装器,日志中的 output 正是我所期望的。 However if I try to run the exe from the command line or from Windows Explorer, nothing happens.但是,如果我尝试从命令行或 Windows Explorer 运行 exe,则没有任何反应。 No error, no output to the console as expected.没有错误,没有按预期向控制台发送 output。 The program is also supposed to edit a text file which does happen when I run the jar using a batch file, but not when I run the exe.该程序还应该编辑一个文本文件,当我使用批处理文件运行 jar 时确实会发生这种情况,但当我运行 exe 时不会发生这种情况。 This is all on the same computer so I doubt it is a problem with the JRE.这一切都在同一台计算机上,所以我怀疑这是 JRE 的问题。 I have searched StackOverflow extensively but found nothing that helps with this situation.我广泛搜索了 StackOverflow,但没有发现任何有助于解决这种情况的信息。 I did find this post with a similar problem: Launch4J executable not executing as expected but nobody actually answered the question.我确实发现这篇文章有类似的问题: Launch4J executable not executing as expected但实际上没有人回答这个问题。 Thank you in advance for helping预先感谢您的帮助

I found the issue.我发现了这个问题。 Under Header, I had to switch the Header type from GUI to Console.在标题下,我必须将标题类型从 GUI 切换到控制台。 After that I was able to run the exe.之后我就可以运行exe了。

您可能会接受一些作为命令行参数的东西,这可能会像我的情况一样抛出错误。

For my case, it was the tick on "Signle Instance" tab: Allow only a single instance of the application.就我而言,它是“Signle Instance”选项卡上的勾号:仅允许应用程序的单个实例。 Although I had killed the process, for some unknown reason the exe had been recognized as alive.尽管我已经杀死了该进程,但出于某种未知原因,该 exe 仍被识别为活着的。 Thus, a reboot of the PC is recommended.因此,建议重新启动 PC。

These are the things I had to do for it to work on Windows 10:这些是我必须做的事情才能在 Windows 10 上工作:

First, make sure the executable JAR you created actually executes.首先,确保您创建的可执行文件 JAR 实际执行。 I could never got the JAR to execute by double-clicking.我永远无法通过双击来执行 JAR。 Instead, I created a .bat file where I added the java -jar command-line instruction to execute the jar, including the VM arguments. For example, to execute foo.jar , the .bat file should contain java -jar --module-path %FX_HOME% --add-modules javafx.controls,javafx.fxml foo.jar .相反,我创建了一个.bat文件,其中添加了java -jar命令行指令以执行 jar,包括 VM arguments。例如,要执行foo.jar.bat文件应包含java -jar --module-path %FX_HOME% --add-modules javafx.controls,javafx.fxml foo.jar Once you get the JAR to execute without errors (pay attention to the command prompt window), then your JAR is ready.一旦你让 JAR 没有错误地执行(注意命令提示符窗口),那么你的 JAR 就准备好了。 Then, do the following from the Launch4J app:然后,从 Launch4J 应用程序执行以下操作:

  1. Create FX_HOME environment variable.创建FX_HOME环境变量。 Make sure it points to the lib folder of the downloaded Java FX distribution is located.*确保它指向下载的 Java FX 分发所在的lib文件夹。*
  2. Set JAVA_HOME environment variable.*设置JAVA_HOME环境变量。*
  3. Make sure JAVA_HOME is the first entry on the Path variable.确保JAVA_HOMEPath变量的第一个条目。 Verify by opening a command prompt and typing where java and hitting the ENTER key.通过打开命令提示符并键入where java并按 ENTER键进行验证。
  4. Under Header, make sure " GUI " is selected.在 Header 下,确保选择了“ GUI ”。
  5. Under JRE, set Bundled JRE paths to %JAVA_HOME% .在 JRE 下,将Bundled JRE paths设置为%JAVA_HOME%
  6. Under VM Option , enter --module-path %FX_HOME% --add-modules javafx.controls,javafx.fxmlVM Option下,输入--module-path %FX_HOME% --add-modules javafx.controls,javafx.fxml

*If any of the paths contain spaces, make sure they are in quotes when you create the environment variable. *如果任何路径包含空格,请确保在创建环境变量时将它们放在引号中。 For example: C:\Program Files\Java 17\bin, should be in quotes.例如:C:\Program Files\Java 17\bin,应该加引号。 This is because the command-line parameters are space-delimited and "Program Files" contains a space, fooling the command-line interpreter to think Program is the end of one parameter and Files is the beginning of another.这是因为命令行参数是用空格分隔的,而“Program Files”包含一个空格,使命令行解释器误认为Program是一个参数的结尾,而Files是另一个参数的开头。 By putting in quotes, the interpreter now knows the space is part of that single parameter that represents the path.通过放入引号,解释器现在知道空格是表示路径的单个参数的一部分。

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

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