Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in thread "main" java.lang.NoSuchMethodError: java.awt.Toolkit.getDefaultToolkit()Ljava/awt/Toolkit; #3

Open
ctoabidmaqbool opened this issue Aug 18, 2024 · 1 comment

Comments

@ctoabidmaqbool
Copy link

I have convert build.sh to compatable build.bat to be executed on Windows OS!

@echo off

echo Creating native image...
native-image --no-fallback ^
             --verbose ^
             -H:ConfigurationFileDirectories=config ^
             -Djava.awt.headless=false ^
             -J-Xmx7G ^
             -jar flatlaf-demo.jar ^
             demo

echo Compressing executable...
upx demo

When I run generated exe, I get errors:

D:\NetBeansProjects\BuildApps\swing-graalvm-demo>demo.exe
Exception in thread "main" java.lang.NoSuchMethodError: java.awt.Toolkit.getDefaultToolkit()Ljava/awt/Toolkit;
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1347)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1332)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetStaticMethodID(JNIFunctions.java:440)
        at [email protected]/java.awt.Toolkit.initIDs(Native Method)
        at [email protected]/java.awt.Toolkit.initStatic(Toolkit.java:1421)
        at [email protected]/java.awt.Toolkit.<clinit>(Toolkit.java:1393)
        at [email protected]/java.awt.EventQueue.invokeLater(EventQueue.java:1316)
        at [email protected]/javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1421)
        at com.formdev.flatlaf.demo.FlatLafDemo.main(FlatLafDemo.java:43)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
@ctoabidmaqbool
Copy link
Author

On executing build.bat:

D:\NetBeansProjects\BuildApps\swing-graalvm-demo>build.bat
Creating native image...
Apply jar:file:///D:/Programs/graalvm-community-jdk-22.0.2_windows-x64_bin/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/thirdparty/native-image.properties
Apply jar:file:///D:/Programs/graalvm-community-jdk-22.0.2_windows-x64_bin/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/polyglot/native-image.properties
Executing [
'INCLUDE=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\ATLMFC\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um' \
'LIB=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\ATLMFC\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22621.0\\um\x64' \
'Path=D:\Programs\gradle-7.3.3-bin\bin;D:\Programs\apache-maven-3.8.8-bin\bin;D:\Programs\graalvm-community-jdk-22.0.2_windows-x64_bin\bin;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\VCPackages;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\DiagnosticsHub\Collector;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\\x64;C:\Program Files (x86)\Windows Kits\10\bin\\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\dotnet\;D:\Programs\ideaIC-2023.3.3.win\bin;D:\xampp1\php;C:\ProgramData\ComposerSetup\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Users\MSC-30\AppData\Local\Microsoft\WindowsApps;D:\Programs\zulu17.48.15-ca-jdk17.0.10-win_x64\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;D:\Programs\gradle-7.3.3-bin\bin;D:\AndroidSDK\platform-tools;C:\Users\MSC-30\AppData\Roaming\npm;C:\Users\MSC-30\.dotnet\tools;C:\Program Files (x86)\WiX Toolset v3.14\bin;C:\Program Files (x86)\Nmap;D:\Programs\ideaIC-2023.3.3.win\bin;C:\Users\MSC-30\AppData\Roaming\Composer\vendor\bin;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\Linux\bin\ConnectionManagerExe;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg' \
'TEMP=C:\Users\MSC-30\AppData\Local\Temp' \
USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=true \
'D:\Programs\graalvm-community-jdk-22.0.2_windows-x64_bin\bin\java.exe' \
-XX:+UseParallelGC \
-XX:+UnlockExperimentalVMOptions \
-XX:+EnableJVMCI \
-Dtruffle.TrustAllTruffleRuntimeProviders=true \
-Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime \
-Dgraalvm.ForcePolyglotInvalid=true \
-Dgraalvm.locatorDisabled=true \
--add-exports=java.base/com.sun.crypto.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.access=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.event=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.loader=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.logger=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.misc=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto \
--add-exports=java.base/jdk.internal.module=org.graalvm.nativeimage.base,org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.org.objectweb.asm=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.perf=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.platform=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.ref=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=java.base/jdk.internal.reflect=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.vm.annotation=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.vm=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.invoke.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.net.www=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.net=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.nio.ch=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=java.base/sun.reflect.annotation=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.factory=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.reflectiveObjects=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.repository=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.scope=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.tree=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.jca=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.ssl=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.x509=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.text.spi=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.calendar=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.cldr=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.locale.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.locale=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.resources=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util=org.graalvm.nativeimage.builder \
--add-exports=java.management/com.sun.jmx.mbeanserver=org.graalvm.nativeimage.builder \
--add-exports=java.management/sun.management=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.aarch64=jdk.graal.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.amd64=jdk.graal.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.site=jdk.graal.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.stack=jdk.graal.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=jdk.graal.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto,org.graalvm.truffle.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.common=jdk.graal.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.aarch64=jdk.graal.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.amd64=jdk.graal.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.riscv64=jdk.graal.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot=jdk.graal.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.meta=jdk.graal.compiler,org.graalvm.nativeimage.base,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto,org.graalvm.truffle.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.riscv64=jdk.graal.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.runtime=jdk.graal.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.services=jdk.graal.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.events=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal.event=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal.jfc=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal=org.graalvm.nativeimage.builder \
--add-exports=jdk.management/com.sun.management.internal=org.graalvm.nativeimage.builder \
-XX:+UseJVMCINativeLibrary \
-Xss10m \
-XX:MaxRAMPercentage=85.0 \
-XX:GCTimeRatio=9 \
-XX:+ExitOnOutOfMemoryError \
-Djava.awt.headless=true \
'-Dorg.graalvm.vendor=GraalVM Community' \
-Dorg.graalvm.vendorurl=https://www.graalvm.org/ \
'-Dorg.graalvm.vendorversion=GraalVM CE 22.0.2+9.1' \
-Dorg.graalvm.version=24.0.2 \
-Dcom.oracle.graalvm.isaot=true \
-Djava.system.class.loader=com.oracle.svm.hosted.NativeImageSystemClassLoader \
-Xshare:off \
-Djdk.reflect.useOldSerializableConstructor=true \
-Djdk.internal.lambda.disableEagerInitialization=true \
-Djdk.internal.lambda.eagerlyInitialize=false \
-Djava.lang.invoke.InnerClassLambdaMetafactory.initializeLambdas=false \
-Djava.lang.invoke.MethodHandle.DONT_INLINE_THRESHOLD=-1 \
-Djava.lang.invoke.MethodHandle.PROFILE_GWT=false \
-Djava.awt.headless=false \
-Xmx7G \
--add-modules=ALL-DEFAULT \
--module-path \
'D:\Programs\graalvm-community-jdk-22.0.2_windows-x64_bin\lib\svm\builder\native-image-base.jar;D:\Programs\graalvm-community-jdk-22.0.2_windows-x64_bin\lib\svm\builder\objectfile.jar;D:\Programs\graalvm-community-jdk-22.0.2_windows-x64_bin\lib\svm\builder\pointsto.jar;D:\Programs\graalvm-community-jdk-22.0.2_windows-x64_bin\lib\svm\builder\svm-foreign.jar;D:\Programs\graalvm-community-jdk-22.0.2_windows-x64_bin\lib\svm\builder\svm.jar' \
--module \
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner \
-keepalive \
'C:\Users\MSC-30\AppData\Local\Temp\.native_image18118768255632354226alive' \
-imagecp \
'D:\NetBeansProjects\BuildApps\swing-graalvm-demo\flatlaf-demo.jar' \
-imagemp \
'D:\Programs\graalvm-community-jdk-22.0.2_windows-x64_bin\lib\svm\library-support.jar' \
'-H:CLibraryPath=D:\Programs\graalvm-community-jdk-22.0.2_windows-x64_bin\lib\svm\clibraries\windows-amd64' \
'-H:Path@driver=D:\NetBeansProjects\BuildApps\swing-graalvm-demo' \
-H:FallbackThreshold@user+api=0 \
'-H:ConfigurationFileDirectories@user=D:\NetBeansProjects\BuildApps\swing-graalvm-demo\config' \
'-H:Name@manifest from file:///D:/NetBeansProjects/BuildApps/swing-graalvm-demo/flatlaf-demo.jar=flatlaf-demo' \
'-H:Class@manifest from file:///D:/NetBeansProjects/BuildApps/swing-graalvm-demo/flatlaf-demo.jar=com.formdev.flatlaf.demo.FlatLafDemo' \
'-H:Name@explicit image name=demo' \
-H:ImageBuildID@driver=2c151a08-9a93-2267-ed2b-40c783d91f35 \
'-H:Features@jar:file:///D:/Programs/graalvm-community-jdk-22.0.2_windows-x64_bin/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/thirdparty/native-image.properties+api=com.oracle.svm.thirdparty.gson.GsonFeature' \
'-H:Features@jar:file:///D:/Programs/graalvm-community-jdk-22.0.2_windows-x64_bin/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/polyglot/native-image.properties+api=com.oracle.svm.polyglot.groovy.GroovyIndyInterfaceFeature,com.oracle.svm.polyglot.scala.ScalaFeature'
]
========================================================================================================================
GraalVM Native Image: Generating 'demo' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------
[1/8] Initializing...                                                                                   (25.7s @ 0.08GB)
 Java version: 22.0.2+9, vendor version: GraalVM CE 22.0.2+9.1
 Graal compiler: optimization level: 2, target machine: x86-64-v3
 C compiler: cl.exe (microsoft, x64, 19.39.33523)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 1 user-specific feature(s):
 - com.oracle.svm.thirdparty.gson.GsonFeature
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 6.22GB of memory (39.1% of 15.91GB system memory, set via '-Xmx7G')
 - 4 thread(s) (100.0% of 4 available processor(s), determined at start)
[2/8] Performing analysis...  [****]                                                                   (171.2s @ 1.10GB)
   10,042 reachable types   (84.8% of   11,844 total)
   21,096 reachable fields  (62.1% of   33,959 total)
   57,125 reachable methods (62.7% of   91,159 total)
    3,177 types,   135 fields, and 1,645 methods registered for reflection
      147 types,   218 fields, and   125 methods registered for JNI access
        3 native libraries: crypt32, ncrypt, version
[3/8] Building universe...                                                                              (23.9s @ 1.28GB)
[4/8] Parsing methods...      [****]                                                                    (16.3s @ 1.43GB)
[5/8] Inlining methods...     [****]                                                                    (11.9s @ 1.59GB)
[6/8] Compiling methods...    [************]                                                           (159.7s @ 1.46GB)
[7/8] Laying out methods...   [****]                                                                    (16.9s @ 1.83GB)
[8/8] Creating image...       [****]                                                                    (19.4s @ 0.95GB)
  29.65MB (54.06%) for code area:    36,425 compilation units
  24.80MB (45.22%) for image heap:  256,196 objects and 142 resources
 403.56kB ( 0.72%) for other data
  54.84MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 origins of code area:                                Top 10 object types in image heap:
  15.51MB java.desktop                                         8.71MB byte[] for code metadata
   6.98MB java.base                                            3.50MB byte[] for java.lang.String
   2.93MB java.xml                                             2.81MB java.lang.Class
   1.98MB flatlaf-demo.jar                                     2.66MB java.lang.String
   1.28MB svm.jar (Native Image)                             862.98kB com.oracle.svm.core.hub.DynamicHubCompanion
 124.01kB java.datatransfer                                  566.98kB byte[] for reflection metadata
 120.56kB java.logging                                       557.45kB java.lang.String[]
  85.64kB jdk.accessibility                                  513.21kB int[][]
  82.60kB java.prefs                                         481.98kB byte[] for general heap data
  70.52kB jdk.proxy1                                         411.55kB byte[] for embedded resources
 240.01kB for 9 more packages                                  3.81MB for 1652 more object types
------------------------------------------------------------------------------------------------------------------------
Recommendations:
 HEAP: Set max heap for improved and more predictable memory usage.
 CPU:  Enable more CPU features with '-march=native' for improved performance.
------------------------------------------------------------------------------------------------------------------------
                       27.2s (6.0% of total time) in 2436 GCs | Peak RSS: 2.58GB | CPU load: 2.26
------------------------------------------------------------------------------------------------------------------------
Build artifacts:
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\awt.dll (jdk_library)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\demo.exe (executable)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\fontmanager.dll (jdk_library)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\freetype.dll (jdk_library)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\java.dll (jdk_library_shim)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\javaaccessbridge.dll (jdk_library)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\javajpeg.dll (jdk_library)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\jawt.dll (jdk_library)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\jsound.dll (jdk_library)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\jvm.dll (jdk_library_shim)
 D:\NetBeansProjects\BuildApps\swing-graalvm-demo\lcms.dll (jdk_library)
========================================================================================================================
Finished generating 'demo' in 7m 34s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant