I am writing a program which I would like to deploy as both desktop and android applications. I want to use JavaFX 2.0 with FXML for the desktop side of things. I want to work entirely in Android Studio. Right now, I am just concerned about producing an desktop executable (for Windows to start with) for my JavaFX program. I'd like to produce an .exe
file if possible, or at least a .jar
.
To clarify, I am not asking how to go about deploying/compiling an existing JavaFX project for Android. I know there exists something called JavaFXPorts for that. I just want to compile and deploy a regular JavaFX program using Android Studio, totally ignoring anything to do with Android for now. (If JavaFXPorts somehow helps with this, then by all means, please show me how).
So far, I've managed to create a regular Java application in Android studio, add in some 'hello world' JavaFX files, and (sort of) deploy the program.
There are many questions squeezed into this one SO question. I don't know where to put my FXML files so that my final Jar file can find them. I think I have to get gradle to copy them to the build directory, but I don't know what the standard way of doing this is. Do I need to put my FXML files in a 'resources' or 'assets' directory? How do I write a gradle script to copy the files over? Should I refer to the FXML files directly, or through the resources system?
It seems that IntelliJ does this automatically using compiler resource settings, but Android Studio is missing this functionality (probably because it assumes I only want to create an Android app, so only need to use the Android resource system).
Just as a reminder, the entire relevant part of my project is located in a 'Java Library' module in the Android Studio project.
I've created an test project which I've uploaded here: https://github.com/Aralox/Android-Studio-FXML-Executable-JavaFX-Project
Here are a few screenshots:
Complaints about a missing 'resources/main' directory. This probably has something to do with the JavaFX gradle script I copied from here. I manually added in this directory for the program to compile (super hacky).
My program couldn't find the FXML file it was looking for because of a change in working directory (hacky way of finding the FXML because using getClass().getResource()
did not work, because the FXML was not copied to the output directory).
Final program working after I manually copied the FXML file into the build directory (and told the program where to find it).
I know this was a long question, but I hope I've made my essential problem clear. The 'child' questions are just problems I encountered in my attempt to find a solution. Thank you very much for the help!