问题
I have completed my JavaFX application within gradle build system, and it is working fine in all way. Now I want to export as a .EXE file for standalone software distribution, I tried much more tricks but no gain. If some one can help me out to wrap my project in a software setup, It would be grateful.
回答1:
Follow these steps to export your JavaFX project into executable Jar
- Goto> Project Structure
- Goto>>Artifacts
- Click "+">> To add new artifact
- It will shows a dropdownlist
- Select>>Jar>>From module with dependencies
- You will see a nested window as shown
- Select Main class of your project
- Check In the Option " Copy to output directory.." >>Ok
- Goto>> Menu-bar>>Build>>Build Artifacts
- Select>> your Project.jar>> Build
- This will create executable jar file in your project source folder
- Locate your jar file in path project\out\artifacts..
- Now you can run this jar file simple cmd commad or with batch file
- Cmd Command>> Java -jar project.jar
Using batch file>> make .bat file name it "RUN" and write these commands inside
Specify the Java Runtime path and "Javafx Sdk path" along with VM options & Project Jar
- Run your standalone application .. Enjoy ;)
回答2:
Creating an installer for the desktop platforms (Windows, macOS, Linux) has become easy these days. The tool of choice is jpackage which started to be shipped with JDK 14. It can either be used on the command line on the finished project or you can use a Gradle plugin (https://github.com/beryx/badass-jlink-plugin). If your project is not modularized you could follow this tutorial https://github.com/dlemmermann/JPackageScriptFX which also uses jpackage but together with Maven and some other tools from the JDK. The Maven part could easily be rewritten to Gradle, if needed.
来源:https://stackoverflow.com/questions/61567231/how-to-export-javafx-gradle-project-as-a-standalone-executable-file-for-deployme