There have been a bunch of questions about how I packaged the FxExperience Tools app. Well this may not be the best way as I have not done this before for Mac and not for Windows for 6 years. So I was learning as I went but here is what I did:
- Do you include JavaFX?
I would recommend that you do as you do not want your end users to have to think about finding and installing the appropriate version of JavaFX. Also if you want to have an exact version that you have done all your testing on then this is the only way to guarantee it.
- Do you include Java JRE?
This is exactly the same as including the JavaFX runtime and has all the same reasons for wanting to do it. For Windows it is a no brainer, just include it. For Mac its a little more complicated at the moment. For 1.6 it should be auto installed for you when needed and you can not redistribute it your self. And when 1.7 is generally available I would recommend packing it in your application.
You need to design a icon for application and make it in a number of different sizes and formats. I designed ours using Photoshop and created PNG files for each of the common sizes 512×512, 256×256, 128×128, 64×64, 32×32 and 16×16. As the icons gets smaller you will need to tweak/simplify the design so that you can still make out what it is showing when only having a few pixels. Once you have all the PNG files with transparency the next stage is to create a .icns file for Mac and a .ico file for Windows. These are special icon file formats that take all the sizes and combine them into a single file. Apple is very nice in providing a great tool for this in their free XCode tools suite. It is called Icon Composer and will take all your images and create both the Mac and Windows icon files for you.
On Mac most applications are shipped as a DMG which is a vertical disk image. Inside of it it contains the Application and a link to the Applications folder so all you have to do to install is Drag and drop. So this is what I created for our FxExperience Tools application so it feels native for Mac users. There are two steps to this process:
Make Mac Application Bundle
For Java 1.6 Apple provides a tool for you called Jar Bundler that takes all your jar files and the jar and jnilib files from JavaFX and packages them into a single Application Bundle. On Mac applications are just special kinds of folders that act like a single file. You can right click and go “Show Package Contents” to see what is inside any application. Other than adding your files, all you need to do is drag and drop in your icon file and specify the main class. Then click “Create Application…” choose a name and you are done.
Make DMG Image containing your Application Bundle
Now that you have your Application Bundle you need to create a zip of DMG so that it can be stored and transmitted by non-macs and over the internet as a single archive. Also it lets you compress it so that it is smaller to download. Although a zip is good enough, a DMG gives you the chance to give your users a nicer experience which is what it is all about on the Mac. So to create a DMG I used the standard Mac tool that comes with every Mac called Disk Utility. So launch Disk Utility and click the “New Image” button, give it a name and keep the standard options. It will create your disk image and open it in finder as a new disk for you. You can then copy your application bundle into it and also create a alias(mac form of linked file) to the applications folder so that your user has a convenient place to drag your application to. Then for a nicer experience it is recommended that you give the disk window a background picture and make it icon view with the tool bar and side bar turned off.
One thing I did learn by mistake is you should put your background image inside your application bundle on the disk image then choose it from there in the view settings dialog. Otherwise it will create a link to it in its absolute location on your machine and will not show on other peoples computers. Last thing then is to size the window to fit your background image and position the window in the center of the screen. Then don’t close the window, just eject the disk using another finder window. Next you can open your DMG back up in Disk Utility and choose “Convert” then save a copy as a compressed format. Then you have your final image ready to ship. When a user opens your DMG they should see something like this:
For windows you need to use a installer maker tool. There are many commercial and free options for this. The one I used is Install4J from ej-technologies. It is commercial but simple to use and polished. It has the nice ability to be able to generate installers for all platforms from all platforms. So on Windows you can create a Mac installer and on Mac you can create a Windows installer. That is handy if you don’t have both platforms handy. At $2000 though its a big investment, but if you’re are shipping a quality application I think it is well worth the investment for the level of polish it offers and the lack of time and hassle of doing your own thing. They do offer free licenses for non-commercial OpenSource projects. I used a old version 3 (the latest is 5) that I had a license for from back when I was running my own startup. I will have to see if I can convince them to gave us a OpenSource license for fxexperience tools project :-). One of the things that it does so well is pack200 and LZMA compressing all the jars that go into the installer. It also makes it very easy to package the JRE inside you application. So for example the windows installer installer is 23Mb download including JavaFX and JRE 1.6 but uncompressed its 100Mb which is very impressive compression. Here is a list of other free windows installer creators that you may want to consider.
This should be simple with any of these installer tools, all you have to do is include the files from the “rt” directory of JavaFX then make sure the javafxrt.jar is in your application class path. Then it should work like magic 🙂
At the moment this is a little complicated process though using a commercial tool really helps. We would love to be able to provide a tool with JavaFX that makes this super simple but I am not sure when we will be able to commit to it. So this is a great place that the open source community could help with. There are loads of open source projects that do parts of it but nothing that does it all in one simple ant task which is what most developers want. So anyone looking to start a open source project and really help out their fellow developers this would be a great project. I would have a go myself if I had the time. Here are some links to other open source projects that solve parts of the problem. I did not find a free tool that lets you create windows MSI installers on Mac or Linux but feel like someone must have made one.
Nice idea for the fx tools package, build the native installer builder, then make a fx interface for it. When done, use itself to build its own package for distribution *vbg*
AFAIK, you can not include JRE (and it seem both JavaFX RT) due to license restrictions. 🙁 strange Oracle policy
I’m not sure this is correct any longer. Can you point to a URL that details this for the current releases?
You should be able to redistribute both JRE and JavaFX 2.0 any released version( i.e. not beta or developer preview). There is a readme in the JRE about what files you have to ship and what you can leave out. For JavaFX for now you have to include all of it. It used to be true that you could not redistribute JavaFX but that was fixed in 2.02 I think. We were depending on a 3rd party library that we were not aloud to allow people to redistrubute. We reimplemented that functionality just to make it possible for you to redistribute. If you have any questions on this contact Nicolas Lorain (@javafx4you) on Twitter.
But, is Pack200 allowed by BCL license (redistribution of a modified binary, even if semantically identical )? [Already asked to Nicolas Lorain]
Are all options of Pack200 allowed (like –strip-debug), because jfxrt.jar can be very reduced with these options?
For information, in my usecase on Windows, I have writed an Ant script for creating:
– A native installer, with 7-Zip SFX.
– A native executable for the application, with Janel.
yep. seems i was wrong
JRE, http://www.oracle.com/technetwork/java/javase/terms/license/index.html & http://www.java.com/en/download/faq/distribution.xml
“Can I distribute Java with my software?
Yes, you can provide Java with your software provided you abide by the terms and conditions of Java binary code license.”
“G. LIMITATIONS ON REDISTRIBUTION. You may not redistribute or otherwise transfer: (a) JavaFX Runtime prior to version 2.0.2, (b) JavaFX Development Kit prior to version 2.0.2, or (c) any and all patches, bug fixes and updates made available by Oracle through Oracle Premier Support, including those made available under Oracle’s Java SE Support program.”
Great post. But what developers and clients really want, isn’t just for the installer to be native, but for the app itself to be native, where the JRE is completely invisible (embedded).
@Clay I think with providing the jre as just a folder in the app’s directory, the client wouldn’t noticed there is a JRE there. Most customers don’t really know much about that stuff in my experience, there is so much more other craps installed in their machines it’s wonder they still work at all
Great details on all the steps you used to create your installers!
If someone wants to skip a lot of the hassle and not have to spend $2,000, take a look at JExpress. It lets you create a professional installer, with your own customized JVM bundle, in 1 step for Windows, Mac and more. JExpress also includes an updater and license tracking.
We offer a free trial version. If your FX Experience is an open source project, let me know. I can get you a free open source license.
Can we use JavaFx for developing of a website like JSP
It is possible to develop website, but not JSP-style (component-base XHTML templating style, that transparently transferred into servlet).
Using JavaFX is a bit similar to java applet. That’s why JRE/JDK must be installed on the _client-side_ with corresponding plugin for browser.
This is the only reason for me not to develop such kind of web application for the Internet. As far as I understand JavaFX can be used for internal intranet application – but anyway there is no difference with a standalone application in this case (JNLP can be used as a launcher).
Thanks for sharing, I created today my first DMG file. 😉
I faced very problems during native installer building process using maven. Finally i have make native installers. please go to this link to find more
I would recommend something like amipackage for javafx to dmg
It is very cheap and gets the job done.