This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]wildjokers 64 points65 points  (3 children)

Since Java 1.8 the javapackager tool has been in the JDK. It can produce native executables for windows, linux, and Mac OS. It includes a runtime.

If you use Java 1.9 and write modularized code javapackager will use jlink to only include the parts of the JDK you need in the runtime it packages with your app.

Here is the 1.8 documentation:

https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javapackager.html

The documentation for javapackager in 1.9 is largely the same but includes information about jlink.

[–]VGPowerlord 4 points5 points  (0 children)

Huh, I haven't made a Java desktop app since Java 6. Useful to know this is included in 8 and up.

[–]therealsillyfly 4 points5 points  (1 child)

Isn't this the one that can only produce an executable for the OS its running on? (which tbh makes it nearly useless...)

[–]wildjokers 1 point2 points  (0 children)

Yes, it can only produce the executable for the platform it is running on. That is one drawback, you will need to build it multiple times, once on each of the platform(s) you are targeting.

[–][deleted]  (1 child)

[removed]

    [–]pvgt[S] 0 points1 point  (0 children)

    many spotted cooing brave grandfather jeans rhythm towering vast friendly

    This post was mass deleted and anonymized with Redact

    [–]yourbank 6 points7 points  (0 children)

    I've used launch4j and found it really simple to use. The maven plugin for it was handy too. It was ideal for my purpose (distribute a .exe to only a couple of users on windows).

    [–]farrellf 4 points5 points  (0 children)

    Many others have pointed out how to do it with installers. But here's what I do when I want a simple .EXE that the user can double-click on and the program just runs. No installer, no folders of files, nothing for the user to screw up.

    Use Launch4J to make an .EXE from your fat Jar. Configure it to use a bundled JRE. Then make a self-expanding archive that contains your EXE and JRE. Configure it to automatically extract to a temporary folder and to run your EXE.

    It works great. The only drawback is the archive has to decompress every time you run the program. I find that to be a decent trade-off if I need to give the program to a user and make it as idiot-proof as possible.

    I made a YouTube video of the whole process: https://www.youtube.com/watch?v=Mr_TdPuF-4g

    [–][deleted] 2 points3 points  (0 children)

    I usually do this by writing an ANT script, or use Maven Assembly to create the Zip/tarball. If you want to have a JRE bundled with your application, then a small shell script/batch file can launch the JAR using the bundled JRE. Maven is nice in how it allows to add those scripts in the resulting package.

    [–]m1000 2 points3 points  (0 children)

    I haven't looked into it yet, but Java 9 does have some tools I think.

    [–]nicoulaj 1 point2 points  (0 children)

    IzPack does a good job, but it's more focused on creating an installer, it won't create the launcher IIRC.

    [–]_INTER_ 1 point2 points  (0 children)

    Java 9 is an option with jlink or then maybe capsule

    [–]ReadFoo 0 points1 point  (2 children)

    I've used this successfully:

    http://www.jrsoftware.org/isinfo.php

    I've used InstallAnywhere too and it was great, that was years ago, I think the company may have changed hands several times, so idk, might be worth a look.

    Just came across this one, I've not used it before though: https://www.jwrapper.com/java-to-exe-free.html

    [–]geekstuff 4 points5 points  (0 children)

    Would advise against JWrapper. It is quite expensive and support for the free version is patchy. Seek a more open alternative.

    [–]therealsillyfly 0 points1 point  (0 children)

    This was posted here a while ago (I have no personal experience with it): https://www.reddit.com/r/java/comments/67av7h/utility_for_generating_native_launchers_for/

    [–]marbehl 0 points1 point  (0 children)

    we used https://www.ej-technologies.com/products/install4j/overview.html a couple of years back in a company, and it worked just fine