Run your Java app as an EXE

My current task is deploying my JavaFX app as an EXE application

Why?

Because, unfortunately, "jar" files aren't looked upon (by windows) as executables which one should only double click in order to run, as if jar files are less legitimate than exe applications.

This is not fair!
People don't like running java applications because they need then to install a Java Virtual Machine, but they forget that in order to run those precious C# applications they need to install the .NET virtual machine, because windows does that automatically with windows updates so it is treansparent, but fundamentally they are the same, both need a virtual machine installed (JRE for java and .NET for .net apps), and a file association in order to run.

Well, as I won't change the world (although I would love to see microsoft having a JRE installed using microsoft [optional] updates), I searched for a solution which will enable me to "convert" my jar file to an EXE file.


Why Not !?

The whole idea behind the java programming language is that it is a cross platform language, so the same jar could run on windows, mac or linux, but when I convert it to an EXE, it will limit my jar severly, having it run only on windows.

But if this is a requirement then that is what I need to do (and maybe have several releases, one for each platform).


How?

The jar to exe conversion can be done in several ways.
An exe can run internally a "java -jar" command (like a batch file)
An exe can contain the jar in it internally and run it

Still, special care should be taken with the JRE, which can be taken care of as follows
The exe can rely on the user pre installing a jre
The exe can ask for a path to the jre
It can parse the system's "JAVA_HOME" environment variable
It can be installed with a zipped or unzipped jre (maybe in a subdirectory)
It can incorporate the whole jre in the exe
It can check for an installed jre upon startup and if not found then can prompt the user to download one


Many options are available for the simple requirement of being able to run a java on windows natively


I am searching for a way to convert my jar to an exe without demanding anything from the user, so I want the whole JRE to be included in that exe as well as the jar, which means that if a user is using windows he will be able to run my app, with no concern that it was ever created using java.

The downside is that my EXE is expected to be very large (at least 50mb) - but I don't care as space is not an issue these days, and of course, it will only work on windows (so the best solution will compile it to all platforms)


Criterias for the application I am searching for:
  • Free (best if it is open source)
  • Maintained
  • Has all features I need
  • Easy enough to use


Solutions I found

The Good
JWrapper - good free option, ended up using this one
Launch4j - Should have worked, but didn't for some reason
Packr - Open source, newest kid in town, but it doesn't incorporate the jre inside the exe, only packs them together (jre in a subdirectory)
Oracle's Bundling Solution as a Maven Plugin - This one was added as an update as I found it only now at 2016 - it just bundles the jre as an external folder but might be worth a try as it looks quite simple to use


The Bad (No good way to use for free)
Excelsior JET - For the rich
Install4j / Exe4j - Looks like a good option if I wanted to spend money


The Ugly
JExeCreator (last version 2012, officialy discontinued)
JNC (Old, and site is down)
JSmooth - Last version 2007, doesn't bundle the JRE, has bugs


Conclusion

A maintained project is an important factor in my requirements, a factor I almost always search for, and especially in this application I am searching for as I know that in the next java release (java9 ?), sun wants to incorporate the jigsaw project, which is a way not to use all of the JRE only parts of it, which means in our case, that in order to use this application with Java9, I will need an apoplication which will be updated to support it.

Thus JSmooth (which actually looks very nice, but is really old), JNC and JExeCreator fell off my grid. (although they are free).

All of the paid apps were disqualified (but if I had to choose a paid one I would check Exe4j), although some of them have a trial edition for free, but in most cases it is time limited and without important features and with big notices to buy the full thing.

Which left me with JWrapper, Launch4j and Packr.
Packr is the newest project (github) and looks like a good candidate if it had more features, as currently it doesn't incorporate the JRE into the executable, just points the jar file to run from a predefined JRE which is in a subdirectory of the build - not good enough, but to be fair, it's name is Packr, so I guess it does its purpose by packing all the parts together.

Launch4j & JWrapper look like good candidates, but for some strange reason I couldn't get launch4j to work as it should although I did dedicate several hours to try and run it as this is the only truly free candidate.
Which left me with JWrapper, which is a paid app but with a free option with all of the features, the only drawback is a splash screen which appears at the first run - I can live with it.

So I suggest using JWrapper, if you need something else I would suggest looking into Launch4j, and if money is not a problem then go for Exe4j.

Comments

Popular posts from this blog

Profiling Java @ 2019

Ant Explorer graphical Ant build tool

What does: "Fault occurred while processing" in the client mean? and how do you reveal the real exception?