Oracle has made it harder to run a JavaFX JAR by just double clicking on something. This template is a "hello world" JavaFX window that can be launched by double clicking the run.vbs script. This template's configurations make it easier to make a user-friendly JavaFX program.
In order to use this template, you need to have Java 15 and IntelliJ IDEA installed on your computer. This repo already contains all the JavaFX 15 stuff.
People who use your program will only need to have Java 15 installed, and they just have to double click on run.vbs.
These instructions are intended for Windows. Maybe I will add macOS and Linux support in the future, but not now. macOS/Linux can do this mostly the same, but with different relative paths, and using a shell script instead of a .bat + a .vbs. They would also need a different version of OpenJFX (for the corresponding OS), as this one currently only has the Windows 64-bit version of OpenJFX 15.
run.vbs runs run.bat without opening a window. If you run run.bat directly, it will open a command prompt window, which users won't want to see. So this template uses a .vbs that runs a .bat that runs a .jar with certain parameters that enable it to work properly with JavaFX. It's a convoluted workaround, but it works. And I already set up most of the complicated stuff, so you just need to follow the instructions.
- Clone the repo
- Open the project folder in IntelliJ
- Click File -> Project Structure -> Libraries -> Click the + icon -> Java
- Navigate to the java15_javafx15_jar_template\openjfx-15_windows-x64_bin-sdk\lib folder and select it
- Click OK
- Click OK when it says "Choose Modules"
- Click Apply
- Click OK
- Click "Add Configuration"
- Click the + icon
- Click Application
- Type "Main" in the "Main class" field (without quotes)
- Copy "--module-path \PATH_TO_OPENJFX\openjfx-15_windows-x64_bin-sdk\javafx-sdk-15\lib --add-modules javafx.controls,javafx.fxml,javafx.graphics,javafx.web" to your clipboard (without quotes and change the \PATH_TO_OPENJFX\ part to whatever makes sense on your system)
- Click in the text field for the "VM options" section
- hit ctrl+v
- Click apply
- Click OK
- If you set up the configuration correctly, it should say "Main" and NOT "Unnamed"
- If it says "Unnamed" then try just replacing either the "Main" or the VM options text again and hit apply and OK again, making sure that it still has the same values as before, but this time changing the name of the configuration to Main
- Hit run to make sure you did everything correctly
- In the left-hand tab, navigate to the Main file in the src folder
- Write your code in the Main class
- Run to make sure it works
- Build -> Build Artifacts -> Build
- Double click the run.vbs script
- You are now running the JAR
You can use this template even without changing the name of the JAR, but just in case you want to change it, here's an example of how to do it. When you change the name of the JAR, there are a few other things that need to change.
- Click File -> Project Structure -> Artifacts
- In the "Name" field towards the top middle, rename "java15_jar_test:jar" to something like "my_program:jar" without quotes (if you use a different name, replace the following instructions' use of "my_program" to your own filename)
- Under the part that says "Output Layout" look for the part that says "java15_jar_test.jar"
- Right click "java15_jar_test.jar and hit "Rename"
- Change the text to "my_program.jar" (without quotes) and hit enter
- Click apply
- Click OK
- Click Build -> Build Artifacts -> my_program:jar -> Build
- In an Explorer window, navigate to the java15_javafx15_jar_template folder
- Right click on run.bat and hit edit to open it with notepad
- On line 4, replace "cd java15_jar_test_jar" with "cd my_program_jar" (without quotes)
- At the end of line 5, replace "java15_jar_test.jar" with "my_program.jar"
- Save the file
For more information, check out this tutorial (I didn't make it): https://www.youtube.com/watch?v=HGHu-SzL-5E