Tag Archives: packaging

Run JavaFx without any prerequisite runtime installation

JavaFx 2.2 recently added the native packaging option during build and can be deployed as executable files  anywhere. This opens up the whole new way how java developer can ship their program to the computers where the latest JRE is not installed.

One of my friend was trying to come up with the Windows GUI program which could run directly from the CD or USB drive in most of the computers. In Indian institutions like schools , the computers are mostly out dated and only has IE 6 browser. HTML5 was not a good idea because it needs the latest browser and it can expose most of  the code and resources on a commercial product. .NET licence was costly considering the small budget project and it was very difficult to find programmers with Delphi and Python (tinka) skills.

Java being so popular language, its very easy to code the GUI quickly, especially in JavaFx. JavaFx have mp3 audio file playing support. Now the big problem was any JavaFx program (jar) needs JavaFx runtime to be installed. This installation could not be expected to be done by school students or people who were new to computers without help of a system administrator. People might not have the correct version of runtime installed and may run into various compatibility issues.

Native packaging allows JavaFx programs to be shipped as exe wrapper file and its own runtime JRE directory.

Since JDK 7 Update 6 , JDK and JavaFx has been merged and there is no separate runtime directories.

One can get get the latest JDK 7u6 beta build(build 14 or later is recommended) On Windows/Mac/Linux it comes with JavaFX 2.2 SDK as part of JDK installation. the “Getting started with native bundles” section of  Java Deployment blog can be referred for the detailed step.

JafaFx_Native
For Netbeans JavaFx project , NetBeans 7.2 is required to support the latest JavaFx 2.2.

  1. Create a new JavaFx project and do you coding.
  2. Locate the project folder (mouse over the project node in the navigation pane ) and open the build.xml
  3. Add nativeBundles=”all” attribute in the deploy tag
  4. Right click on the project tag and select “clean and build”
  5. Go back to the project folder and you can find the “bundles” folder in the usual “dist” folder.
  6. Inside the “bundles” folder there will be another folder with the project name and the executable will be inside it.
  7. Now you can double click and run the program.
  8. The “app” directory would contain the jar distribution archive.
  9. The folder called “runtime” contains the whole JRE (that includes the JavaFx runtime in the latest version)
  10. The whole bundle is portable to most of the computers, I have tested it in a computer where no Java is installed.
It is always recommended to have Java installed in all the computers for better performance and running other application but native packaging is very useful for light weight programs and a greater outreach.
More Help

Alternatively once can convert the jar files to windows executable and bundle with its own JRE with Launch4J. It worked fine for JavaSwing programs but got JavaFx runtime error in some computers.