I have created a run time image for my Java application using jlink and I would like to be able to ship my app as an executable to different platforms.
Ideally, it would be a single file that a user can double click and start the application without the need for installing anything.
Is there currently a good way to do this?
Double click to run executables on multiple platforms, requires prior registration of the file type with the operating system, or an existing file type to know how to handle the code.
jlink statically links the "required modules and their transitive dependencies" to the output.
There is no cross platform solution to this problem.
It is improbable(or to put it another way, not feasible) to include all platforms in a single file, since each executable type(COFF, ELF...), has a different structure. You could attempt to use a generic batch file to start the proper executable, but on Windows, that would require a text file type encoding; thus poisoning the remaining binary code.
Using jlink and the new jmod file format will allow you store native code in a Java container, and thus allowing the entry point into the embedded native JRE code in a single executable image for a single pre-defined platform.
The other side of this issue is the security implications. Since the embedded JRE is not subject to security updates, crackers may choose to embed a previously known flawed JRE, thus exposing corrected exploits to unknowing consumers.
The expected response from Anti-Virus programs would be to flag all non-updated embedded JRE's as viruses.
Also, have a look at SubstrateVM. This is not a true Java, however, it may help you in some cases like simple command line applications.
You can make an installer that installs the JDK and the application. Make the application an exe by using something like Launch4j and for a Mac executable follow this tutorial by Oracle: Packaging a Java App for Distribution on a Mac and lastly: For Linux
Minecraft uses this method and as far as that i don't know any other way.
If you want to make portable application, "make once run anywhere" type app then I'd suggest trying out a different programming language like C# which also requires the .NET JVM but is embedded in Windows systems.
Yes, as of Java 8 there are two ways of doing this, using the javapackager tool, or the JavaFX Ant Tasks (which aren't actually specific to JavaFX, and are provided with the Java 8 JDK).
Here's an example of packaging an application as a Jar, setting the main-class and classpath attributes, and copying all the dependencies into a folder, using Maven.
And here is the Ant build file to package the standalone application (exe for Windows, .app and .dmg on OS X, .deb and .rpm on Linux).