How to export JavaFX gradle project as a standalone executable file for deployment?

我是研究僧i 提交于 2020-06-27 16:48:08

问题


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

  1. Goto> Project Structure
  2. Goto>>Artifacts
  3. Click "+">> To add new artifact
  4. It will shows a dropdownlist
  5. Select>>Jar>>From module with dependencies
  6. You will see a nested window as shown
  7. Select Main class of your project
  8. Check In the Option " Copy to output directory.." >>Ok
  9. Goto>> Menu-bar>>Build>>Build Artifacts
  10. Select>> your Project.jar>> Build
  11. This will create executable jar file in your project source folder
  12. Locate your jar file in path project\out\artifacts..
  13. Now you can run this jar file simple cmd commad or with batch file
    • Cmd Command>> Java -jar project.jar
  14. Using batch file>> make .bat file name it "RUN" and write these commands inside

  15. Specify the Java Runtime path and "Javafx Sdk path" along with VM options & Project Jar

  16. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!