DEV Community

Discussion on: Creating a native executable in Windows with GraalVM

Collapse
 
shashaanktulsyan profile image
Shashank Tulsyan • Edited

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.

\graalvm-ce-19.0.2\bin\native-image.cmd -H:+ReportExceptionStackTraces -H:JNIConfigurationFiles=jniconfig.json -H:ReflectionConfigurationFiles=reflectconfig.json -Djavafx.verbose=true -Dprism.verbose=true -Djava.library.path=\graalvm-ee-19.0.2\jre\bin -cp \graalvm-ee-19.0.2\jre\lib\ext\jfxrt.jar -jar thejavafxproject.jar 

I am able to get a native image, which will crash :'(

reflectconfig.json

[
  {
    "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" : "<init>", "parameterTypes" : [] },
      { "name" : "<init>", "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" : "<init>", "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

[
  {
    "name" : "com.sun.prism.impl.PrismSettings",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredClasses" : true,
    "allPublicClasses" : true,
    "allPublicFields" : true
  }
]

A 10MB exe is created thejavafxproject.exe

> thejavafxproject.exe  -Djavafx.verbose=true -Dprism.verbose=true -Djava.library.path=graalvm-ee-19.0.2\jre\bin\

Output - on running the executable

Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-console-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-datetime-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-debug-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-errorhandling-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-file-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-file-l1-2-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-file-l2-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-handle-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-heap-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-interlocked-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-libraryloader-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-localization-l1-2-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-memory-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-namedpipe-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-processenvironment-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-processthreads-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-processthreads-l1-1-1.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-profile-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-rtlsupport-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-string-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-synch-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-synch-l1-2-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-sysinfo-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-timezone-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-core-util-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-conio-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-convert-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-environment-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-filesystem-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-heap-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-locale-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-math-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-multibyte-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-private-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-process-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-runtime-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-stdio-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-string-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-time-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\api-ms-win-crt-utility-l1-1-0.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\ucrtbase.
dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\vcruntime
140.dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\msvcp140.
dll from java.library.path
Loaded \graalvm-ee-19.0.2\jre\bin\concrt140
.dll from java.library.path
Prism pipeline init order: d3d sw
Using native-based Pisces rasterizer
Using dirty region optimizations
Not using texture mask for primitives
Not forcing power of 2 sizes for textures
Using hardware CLAMP_TO_ZERO mode
Opting in for HiDPI pixel scaling
Prism pipeline name = com.sun.prism.d3d.D3DPipeline
(X) Got class = class com.sun.prism.d3d.D3DPipeline
Loading D3D native library ...
Loaded \graalvm-ee-19.0.2\jre\bin\prism_d3d
.dll from java.library.path
        succeeded.
D3DPipelineManager: Created D3D9Ex device
Direct3D initialization succeeded
Initialized prism pipeline: com.sun.prism.d3d.D3DPipeline
JavaFX: using com.sun.javafx.tk.quantum.QuantumToolkit
Loaded graalvm-ee-19.0.2\jre\bin\glass.dll
 from java.library.path
Collapse
 
skhmt profile image
Mike

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!

Collapse
 
shashaanktulsyan profile image
Shashank Tulsyan • Edited

Ya just to come and report, it works. Gluon team did the hard-work and it is for free for all of us.
preview