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. However if I try to run the exe from the command line or from Windows Explorer, nothing happens. No error, no output to the console as expected. 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. This is all on the same computer so I doubt it is a problem with the JRE. I have searched StackOverflow extensively but found nothing that helps with this situation. I did find this post with a similar problem: Launch4J executable not executing as expected but nobody actually answered the question. Thank you in advance for helping
I found the issue. Under Header, I had to switch the Header type from GUI to Console. After that I was able to run the exe.
You may be accepting something as a command line argument which may be throwing an error like in my case .
For my case, it was the tick on "Signle Instance" tab: Allow only a single instance of the application. Although I had killed the process, for some unknown reason the exe had been recognized as alive. Thus, a reboot of the PC is recommended.
These are the things I had to do for it to work on Windows 10:
First, make sure the executable JAR you created actually executes. I could never got the JAR to execute by double-clicking. 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
. Once you get the JAR to execute without errors (pay attention to the command prompt window), then your JAR is ready. Then, do the following from the Launch4J app:
- Create FX_HOME environment variable. Make sure it points to the lib folder of the downloaded Java FX distribution is located.*
- Set JAVA_HOME environment variable.*
- Make sure JAVA_HOME is the first entry on the Path variable. Verify by opening a command prompt and typing
where java
and hitting the ENTER key. - Under Header, make sure "GUI" is selected.
- Under JRE, set Bundled JRE paths to %JAVA_HOME%.
- Under VM Option, enter
--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. 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. By putting in quotes, the interpreter now knows the space is part of that single parameter that represents the path.
In my case, under Basic tab in Options section I checked "Stay alive after launching GUI application" (this doesn't work).
Instead I switched to jSmooth.
© 2022 - 2024 — McMap. All rights reserved.
<classpath>
configuration entry helped. #2068633 – Otiose