GraalVM tips in Windows

2022-11-24  本文已影响0人  山哥Samuel

Generate Native Image

Prerequisites

set INCLUDE=<Copy from another good machine>
set LIB=<Copy from another good machine>

Sometimes the Anti-Virus tool will block you from creating files at C:\Users\<user>\AppData\Local\Temp. To make your life easier, you might change the TEMP and TMP variable by:

set TMP=c:\Temp
set TEMP=c:\Temp

For Swing / Awt related application. You might encounter below errors. You can avoid them by the Step-by-steps section.

# Error 1:
Exception in thread "AWT-EventQueue-0" java.lang.Error: java.home property not set


# Error 2: 
xception in thread "main" java.lang.UnsatisfiedLinkError: no awt in java.library.path
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryRelative(NativeLibrarySupport.java:120)

Step-by-steps

  # -O0 for testing purpose, it will not optimize the exe
  > native-image -O0 -o my-exe-file -jar <project base>\target\my-jar.jar --initialize-at-build-time=org.slf4j.LoggerFactory -H:+ReportExceptionStackTraces
SEVERE: Unable to initialize BouncyCastleAlpnSslUtils.
java.lang.ClassNotFoundException: org.bouncycastle.jsse.BCSSLEngine

Error: No instances of java.net.Inet4Address are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked.
Trace: Object was reached by ...

Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of java.net.Inet4Address are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked.
  # Now optimize it 
  > native-image -H:Name=my-exe-file -jar <project base>\target\my-jar.jar --initialize-at-build-time=org.slf4j.LoggerFactory -H:+ReportExceptionStackTraces -o my-exe-file -O3
> dir lib
2022/11/24  17:58    <DIR>          .
2022/11/24  17:58    <DIR>          ..
2022/10/20  12:43             4,630 fontconfig.bfc
2022/10/20  12:43            12,345 fontconfig.properties.src
2022/10/20  12:43             3,793 psfont.properties.ja
2022/10/20  12:43            11,390 psfontj2d.properties
-- parent folder
  |-- bin (The files inside is generated by the graal-vm automatically)
       |-- my-exe.exe
       |-- jvm.dll
       |-- awt.dll
       |-- ... (some other dll files)
  |-- lib (this one nees to be manually prepared)
       |-- fontconfig.bfc
       |-- fontconfig.properties.src
       |-- psfont.properties.ja
       |__ psfontj2d.properties
上一篇 下一篇

猜你喜欢

热点阅读