GraalVM is pretty awesome for a lot of reasons. But the one that has me most hyped is the ability to create native executables from Java bytecode. This isn't like ExcelsiorJET (R.I.P.), which makes you include a large runtime, nor is it like Launch4J and Oracle's javapackager
tool, both of which create a dummy executables that points to your .jar
and a packaged JRE.
GraalVM makes real native executables without a packaged runtime.
Unfortunately, GraalVM's native-image
, and indeed its entire support for Windows, is in early adopter status. There are some error messages that aren't accurate, some bugs, and some features missing.
But it does work, more-or-less.
Things to know before you get started
There's about a 8.5 MB minimum file size for a bare bones hello world
java application. That's kind of a lot, but also a lot less than including the entire JRE.
Some other articles or guides recommend installing Git for Windows and Python 2.7, but I'm like 99% sure that's for building GraalVM before running.
All the Swing and JavaFX applications I've tried haven't been able to build in the Windows version of native-image
in 19.0.0.
The Image Generation Options page is a good resource for troubleshooting, you may have to place some of your classes into the --initialize-at-run-time=<comma separated list of class/package names>
option.
Steps to run GraalVM 19.0.0's native-image
in Windows
- Uninstall any
Visual C++ 2010 Redistributable
s - Get the Windows version of GraalVM 19.0.0: https://github.com/oracle/graal/releases/tag/vm-19.0.0
- Extract it somewhere easy to find
- Get the Microsoft Windows SDK for Windows 7 and .NET Framework 4 (ISO): https://www.microsoft.com/en-us/download/details.aspx?id=8442
- Mount the image, open
F:\Setup\SDKSetup.exe
directly - A default install should be perfect
-
Run the Windows SDK 7.1 Command Prompt by going to
Start
>Microsoft Windows SDK v7.1
>Windows SDK 7.1 Command Prompt
- Run one of these commands based on if you have a
.jar
or a.class
:
\path\to\graalvm-ce-19.0.0\bin\native-image -jar \path\to\helloworld.jar --no-fallback
or
\path\to\graalvm-ce-19.0.0\bin\native-image \path\to\helloworld.class --no-fallback
The *.exp
, *.lib
, and *.pdb
files seem to be artifacts of the build process, they're not required for distribution.
But that's it, your .exe
is made!
Update: As of GraalVM 19.3.0, still no support for Swing nor JavaFX.
For GraalVM 19.3.0 on Windows with the new support for Java 11, you'll need Visual Studio 2017 Community Edition
instead of the Microsoft Windows SDK for Windows 7
, which you can get here with a free Visual Studio Dev Essentials account. Instead of running the Windows SDK 7.1 Command Prompt
, you'll of course run x64 Native Tools Command Prompt for VS 2017
as your command line in Start
> Visual Studio 2017
.
Gluon is working on providing JavaFX support for 19.3.0 - it already has it for macOS and Linux, and Windows should be coming soon.
Finally, if you do distribute an exe made with native-image on windows, you will need to include vcruntime140.dll
with it, which is about 84kb.
Top comments (4)
I tried to make graal native image to work for javafx, and failed, leaving notes for the record.
Even after making several configurations changes I am not able to get it to work.
The project I am compiling is thejavafxproject
with the entry point - JavaFxEntryPointMainMethod
This is the command I used to build the native image.
[
{
"name" : "java.lang.Class",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredClasses" : true,
"allPublicClasses" : true
},
{
"name" : "java.lang.String",
"fields" : [
{ "name" : "value", "allowWrite" : true },
{ "name" : "hash" }
],
"methods" : [
{ "name" : "", "parameterTypes" : [] },
{ "name" : "", "parameterTypes" : ["char[]"] },
{ "name" : "charAt" },
{ "name" : "format", "parameterTypes" : ["java.lang.String", "java.lang.Object[]"] }
]
},
{
"name" : "java.lang.String$CaseInsensitiveComparator",
"methods" : [
{ "name" : "compare" }
]
},
{
"name" : "thejavafxproject.JavaFxEntryPointMainMethod"
},
{
"name" : "com.sun.javafx.tk.quantum.QuantumToolkit",
"methods" : [
{ "name" : "", "parameterTypes" : [] }
]
},
{
"name" : "com.sun.prism.d3d.D3DPipeline",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredClasses" : true,
"allPublicClasses" : true
},
{
"name" : "com.sun.prism.impl.PrismSettings",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredClasses" : true,
"allPublicClasses" : true,
"allPublicFields" : true
},
{
"name" : "com.sun.glass.ui.win.WinPlatformFactory",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredClasses" : true,
"allPublicClasses" : true,
"allPublicFields" : true
}
]
~~~~
jniconfig.json
Output - on running the executable
Good attempt! Gluon is supposedly going to release a Maven/Gradle plugin to get javafx working with openjdk and graalvm for Windows "shortly." They just recently released the beta version for macOS, so I have high hopes!
Ya just to come and report, it works. Gluon team did the hard-work and it is for free for all of us.
aww, thats cool. ♥️