Simple demo for small features making GraalVM native images more Windows-friendly.
Started due to almost complete lack of info about things like that, and my frustration about GraalVM treating GUI apps as third-class citizens.
I assume you already know the basics of GraalVM, and have an environment on which you can at least compile "hello world" examples.
Making app request admin rights on start.
Preventing app from starting a text console if it's not already present.
Changing main icon.
Changing version info.
Pretty much any distribution of GraalVM for Java 21 should work.
The configuration I'm writing it on is:
Windows 11 Pro, Netbeans 18, Visual Studio Community 2022, Resource Hacker 5.1.7, Liberica NIK 23.1.0 Full
Add the following to native-maven-plugin configuration:
<arg>-H:NativeLinkerOption=/MANIFEST:EMBED</arg>
<arg>-H:NativeLinkerOption=/MANIFESTUAC:level='requireAdministrator'</arg>
Add the following to native-maven-plugin configuration:
<arg>-H:NativeLinkerOption=/SUBSYSTEM:WINDOWS</arg>
<arg>-H:NativeLinkerOption=/ENTRY:mainCRTStartup</arg>
See: https://learn.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol?view=msvc-170
JavaFX still doesn't have some basic functionality, such as tray icon support.
Add something like that to native-maven-plugin configuration:
<arg>-H:NativeLinkerOption=${project.basedir}\src\main\resources\windows\mainicon.res</arg>
<arg>-H:NativeLinkerOption=${project.basedir}\src\main\resources\windows\ver.res</arg>
.res files contain various pieces of information that can be merged into a Windows exe. They can contain all kinds of stuff, but we're mostly interested in these two.
You can make them with Resource Hacker (which is freeware), either entirely in it's GUI or using it as a compiler for .rc files. .rc files are human-readable definitions.
.ico files are specific to Windows, they're a special kind of bitmap files with certain icon-specific requirements. The easiest way to make them is with Paint.NET with IconCreator plugin. GIMP supports them too. If you make them from scratch you probably want them to be 64x64 or 32x32.
No, you can't use .png or .jpg files, it has to be .ico format. Of course, you can convert other formats to .ico.
You're getting the point. It is "C++ stuff", which IMHO should be exposed by GraalVM build tools. Instead you have to use things like "-H:NativeLinkerOption" to forward extra instructions to native Windows build tools.
If you have any further questions you're more likely to find the answers on Microsoft site.
Hopefully. I see no reasons why it shouldn't, but there are no guarantees either.
No. GraalVM native images support only 64-bit Windows.
I don't see why not. Pretty much all of it is using "-H:NativeLinkerOption" to give extra instructions to the linker. Should work with Java 11 too.
Because it was the latest LTS at the time of writing.
It's supposed to be easy to understand, not a "best practices".
Why do you use /META-INF/native-image/${project.groupId}/${project.artifactId}/generated instead of /META-INF/native-image/${project.groupId}/${project.artifactId}?
Personal preference. The idea is to gather data from the agent into /generated folder, then move selected portions into a sibling /manual folder, with GraalVM using both.
Personally I consider stuff like that "too simple to claim ownership to".
MIT. Basically "do whatever, don't blame me".
I want to like it. But after all that waiting I still don't think it's production-ready, at least not for GUI apps. If it were that project would be completely unnecessary.
Feel free to donate: