A method to pack javafx apps in less than 5 MB (with jvm)

Shashaank Tulsyan shashaanktulsyan at gmail.com
Wed Apr 8 18:46:57 UTC 2015


Hi,

I am extremely excited to share something unimaginable.
Inspired by various open source projects out there I tried to create an
insanely stripped down vm distribution.

The result :
Java 8 FX app in less than 5MB !!!!!

Don't believe me, just see it for yourself :
https://github.com/s...0application.7z
<https://github.com/shashaanktulsyan/spyfs/blob/master/sample%205MB%20java%20application.7z>
*Note1 : This app has been packaged using javafx packer and for some reason
will not run on 32bit OS.*
*Note2 : This app does nothing, it will just show a javafx window, with a
button that does nothing**.*

For me having a *desktop* java app, along with java runtime, in less than
5MB is a big deal.
You might not believe me, but I have been waiting for java modularization
to happen since almost a decade.
I started doing java when I was 15, and hated that I couldn't distribute
stuff that I made like others were able to using other languages.
Anyhow, I would like to share how I achieved this.

I used following facts to my advantage :

   - Java classes are loaded in lazy fashion. So even if there is
   dependency to a class because of an import statement, the class itself will
   not be loaded until it is required !
   - Xbootclasspath can be used to change runtime classes. So instead of
   using heavy rt.jar and other heavy jar files we can use a highly stripped
   down runtime which has exactly those classes which we require. (Inspired by
   robovm, retrolamba and proguard)
   - So now the last part remains, is *how to find which classes are
   actually used*. For this purpose I don't use anything related to javavm.
   Instead I use kernel level *virtual filesystems*!!! This way I am also
   able to remove native libraries (dlls) and resources (configuration files
   etc) which are not required.
   - Finally these options can be set very easily in configuration file of
   a native java application created using javafx packager. Only 2 lines need
   to be added to do the trick.



Here I am not going to share the details.
But I am here to share the excitement. This is really insanely small !
A Javafx application in 5MB!! That is crazy small.

This is a very rigorous approach, only very greedy might go to this path.
But when you see other platforms/vms/languages giving out small 5MB native
apps, one feels why can't java also do this? :D

It just shows how much room we have for stripping down jvm. It shows that
the smallest base that we start off with can be very very small.

What do you guys think?
BTW if you are interested in knowing the exact steps, check out
https://github.com/shashaanktulsyan/spyfs#java-in-5-mb

Thanks
Shashank [image: :D] [image: :D] [image: :D]


More information about the jigsaw-dev mailing list