Closed
Description
Describe the issue
When compiling my simple hello world Swing application on Windows using native-image, it does not work.
Steps to reproduce the issue
- Write a simple Swing application on Windows
- Compile it into a executable JAR
- Verify the executable JAR works as intended
- Use native-image to compile the JAR into an EXE using e.g.
native-image -jar "Hello World.jar" "Hello World"
- An exception occurs:
Fatal error:com.oracle.svm.core.util.VMError$HostedError: should not reach here
Describe GraalVM and your environment:
- GraalVM version: https://github.com/graalvm/graalvm-ce-dev-builds/releases/tag/21.3.0-dev-20210806_1944
- JDK major version: 16
- OS: Windows 10 64-bit
- Architecture: AMD64
More details
>native-image -jar "Hello World.jar" "Hello World" --verbose
Executing [
'C:\graalvm_jdk16\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 \
-Dsubstratevm.IgnoreGraalVersionCheck=true \
--add-exports=java.base/com.sun.crypto.provider=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.access.foreign=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.event=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.loader=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.logger=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.module=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.org.xml.sax.helpers=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.perf=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.util.xml.impl=ALL-UNNAMED \
--add-exports=java.base/jdk.internal.util.xml=ALL-UNNAMED \
--add-exports=java.base/sun.invoke.util=ALL-UNNAMED \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.annotation=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.generics.repository=ALL-UNNAMED \
--add-exports=java.base/sun.reflect.generics.tree=ALL-UNNAMED \
--add-exports=java.base/sun.security.jca=ALL-UNNAMED \
--add-exports=java.base/sun.security.provider=ALL-UNNAMED \
--add-exports=java.base/sun.security.util=ALL-UNNAMED \
--add-exports=java.base/sun.text.spi=ALL-UNNAMED \
--add-exports=java.base/sun.util.calendar=ALL-UNNAMED \
--add-exports=java.base/sun.util.locale.provider=ALL-UNNAMED \
--add-exports=java.base/sun.util.resources=ALL-UNNAMED \
--add-exports=java.xml.crypto/org.jcp.xml.dsig.internal.dom=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.aarch64=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.amd64=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.site=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.stack=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.common=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.aarch64=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.amd64=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.meta=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.runtime=ALL-UNNAMED \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.services=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.events=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.internal.consumer=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.internal.handlers=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.internal.jfc=ALL-UNNAMED \
--add-exports=jdk.jfr/jdk.jfr.internal=ALL-UNNAMED \
-XX:+UseJVMCINativeLibrary \
-Xss10m \
-Xms1g \
-Xmx14g \
-Duser.country=US \
-Duser.language=en \
-Djava.awt.headless=true \
-Dorg.graalvm.version=21.3.0-dev \
-Dorg.graalvm.config=CE \
-Dcom.oracle.graalvm.isaot=true \
-Djava.system.class.loader=com.oracle.svm.hosted.NativeImageSystemClassLoader \
-Xshare:off \
--module-path \
'C:\graalvm_jdk16\lib\truffle\truffle-api.jar' \
-Djdk.internal.lambda.disableEagerInitialization=true \
-Djdk.internal.lambda.eagerlyInitialize=false \
-Djava.lang.invoke.InnerClassLambdaMetafactory.initializeLambdas=false \
'-javaagent:C:\graalvm_jdk16\lib\svm\builder\svm.jar' \
-cp \
'C:\graalvm_jdk16\lib\svm\builder\objectfile.jar;C:\graalvm_jdk16\lib\svm\builder\pointsto.jar;C:\graalvm_jdk16\lib\svm\builder\svm.jar' \
'com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus' \
-imagecp \
'D:/JavaProjects/Hello World GraalVM\Hello World.jar;C:\graalvm_jdk16\lib\svm\library-support.jar' \
'-H:Path=D:/JavaProjects/Hello World GraalVM' \
'-H:Class@manifest from file:///D:/JavaProjects/Hello%20World%20GraalVM/Hello%20World.jar=Main' \
'-H:Name@manifest from file:///D:/JavaProjects/Hello%20World%20GraalVM/Hello%20World.jar=Hello World' \
'-H:CLibraryPath=C:\graalvm_jdk16\lib\svm\clibraries\windows-amd64' \
'-H:Name@explicit image name=Hello World'
]
[Hello World:21804] classlist: 1,425.84 ms, 0.96 GB
[Hello World:21804] (cap): 1,848.14 ms, 0.96 GB
[Hello World:21804] setup: 3,349.53 ms, 0.96 GB
[Hello World:21804] (clinit): 466.52 ms, 3.79 GB
[Hello World:21804] (typeflow): 10,202.45 ms, 3.79 GB
[Hello World:21804] (objects): 8,178.93 ms, 3.79 GB
[Hello World:21804] (features): 900.09 ms, 3.79 GB
[Hello World:21804] analysis: 21,964.79 ms, 3.79 GB
[Hello World:21804] universe: 1,774.63 ms, 3.79 GB
[Hello World:21804] (parse): 1,473.85 ms, 3.80 GB
[Hello World:21804] (inline): 1,953.48 ms, 4.24 GB
[Hello World:21804] (compile): 23,004.54 ms, 4.86 GB
[Hello World:21804] compile: 27,992.96 ms, 4.86 GB
[Hello World:21804] image: 2,549.32 ms, 4.86 GB
[Hello World:21804] write: 1,058.40 ms, 4.86 GB
Fatal error:com.oracle.svm.core.util.VMError$HostedError: should not reach here
at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:64)
at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLL(JNIRegistrationSupport.java:256)
at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLLs(JNIRegistrationSupport.java:230)
at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.afterImageWrite(JNIRegistrationSupport.java:175)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$8(NativeImageGenerator.java:667)
at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:73)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:667)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:492)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:400)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:566)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:596)
[Hello World:21804] [total]: 60,342.13 ms, 4.86 GB
# Printing build artifacts to: D:\JavaProjects\Hello World GraalVM\native\Hello World.build_artifacts.txt
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1867)
at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1512)
at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1473)
at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1460)
What's the current state of Swing support for Windows? Since Windows is the most popular desktop OS, I don't understand why apparently only Linux support has been implemented. Is there any command line switch or similar I can try to potentially make it work for Windows right now?
Related issue: #1327
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
chirontt commentedon Aug 9, 2021
This is similar to #3575
You must run your Swing app with the native-image-agent to generate the config files for the native-image command to use.
Also, try using the GraalVM version for JDK11, as the JDK16 version may be problematic (it's experimental status, after all)
munishchouhan commentedon Aug 12, 2021
@BullyWiiPlaza as suggested by @chirontt
please use native-image tracing agent
https://docs.oracle.com/en/graalvm/enterprise/21/docs/reference-manual/native-image/Agent/
and GraalVM-21.2-Java11
BullyWiiPlaza commentedon Aug 15, 2021
I used the Java 11 version of GraalVM before but got the same error using the Java 16 version so I thought the latest version has the best chances to work.
However, now I setup a new project with similar code and the native-image compilation actually succeeded. Though, upon running the EXE it crashed and I got the following exception:
After tracing all API usages using the tracing agent and adding the configs to the
META_INF/native-image
directory inside my JAR, I got the following different exception(s) upon running:Looks like this is related to #1812 which is still an open issue so there does not seem to be a fix yet.
munishchouhan commentedon Aug 16, 2021
@BullyWiiPlaza please try GraalVM 21.3-dev
https://github.com/graalvm/graalvm-ce-dev-builds/releases/tag/21.3.0-dev-20210813_0049
and let us know the output
chirontt commentedon Aug 17, 2021
@BullyWiiPlaza, for your
java.lang.Error: java.home property not set
error, which only happens in Windows native image, there are many ways to work around it. The simplest way is to invoke your native executable with thejava.home
system property pointing to your JDK, i.e.your-app.exe -Djava.home=%JAVA_HOME%
BullyWiiPlaza commentedon Aug 19, 2021
I downloaded https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/21.3.0-dev-20210813_0049/graalvm-ce-java11-windows-amd64-dev.zip and used that version now (see results below).
It gives a
NullPointerException
instead now. MyJAVA_HOME
is set of course:munishchouhan commentedon Aug 19, 2021
@BullyWiiPlaza
please check this issue
#3393
there is a solution for InvocationTargetException
chirontt commentedon Aug 19, 2021
@BullyWiiPlaza
The
java.lang.NullPointerException
is caused by the space character in yourJAVA_HOME
setting!You should escape it with double-quotes:
>Prime-Numbers-Calculator.exe -Djava.home="%JAVA_HOME%"
BullyWiiPlaza commentedon Aug 19, 2021
Wow, now it works and the GUI loads up, thanks for the patience.
However, when I drag the GUI around in my other monitor it throws the following exception repeatedly:
This seems like something Oracle has forgotten to handle properly.
Also the following exception came up after clicking the "Calculate" button for prime numbers:
Actually, even more events seem to be non-implemented:
Interacting with the
JTextArea
is rough and throws exceptions.Neither of those exceptions come up with the regular executable Jar. Other than that, the toy application works now. 👍
If I'm required to trace all possible Swing GUI events before being about to properly compile, that's not very practical, even for a toy program.
munishchouhan commentedon Aug 20, 2021
@BullyWiiPlaza AWT and wing support for windows is still a work in progress, please follow the below issue for more information
#3084
munishchouhan commentedon Sep 27, 2021
Closing this because there is no activity in last 30 days
JFWPublic commentedon Oct 19, 2022
This issue seems to still exist. I just compiled my simple Swing application and upon running I get:
Exception in thread "main" java.lang.NoSuchMethodError: java.awt.Toolkit.getDefaultToolkit()Ljava/awt/Toolkit;
I'm using GraalVM for Java 17 Windows amd64 v22.2.0
ShanGor commentedon Nov 24, 2022
You can manually copied some small files of the JAVA_HOME\lib to solve the problem in windows. And run with -Djava.home=.
Ref to https://jianshu.com/p/a53ae350f845?v=1669292961020
tlf30 commentedon May 8, 2023
For anyone who gets here troubleshooting, here was my solution:
In gradle, I created a target that copies the compiled natives into
build/dist
and the necessary jdk files intobuild/dist/lib
At the very beginning of my app (Very first thing in main) I did this:
This causes the swing font data to get looked up from the
lib/
dir next to the executable.risharde commentedon May 25, 2023
Am I misunderstanding the purpose of GraalVM Native Image? Shouldn't the executable not be dependent on the java.home files? I'm having the same issue as the original user. This is so confusing.
YektaDev commentedon Aug 22, 2023
The Swing/AWT issue still exists with the latest version of JDK 20 (
graalvm-community-openjdk-20.0.2+9.1
)Even with providing the configurations, I face the below exception upon execution (on Windows 11):
I know #3084 is still open, but it's been almost three years and I hope it gets addressed one day...
lyjia commentedon Aug 25, 2023
Hi,
I just want to note that the
java.lang.NoSuchMethodError: java.awt.Toolkit.getDefaultToolkit()Ljava/awt/Toolkit
seems to be resolvable by running the java agent that outputs totarget/native/agent-out
, per https://www.graalvm.org/22.2/reference-manual/native-image/guides/use-native-image-maven-plugin/ (section "Build a Native Executable with Maven"), but when I do this the produced executable then throwsjava.lang.Error: java.home property not set
.Using graalvm 20 on Windows, compiling a Swing app with FlatLaf and miglayout (and no other dependencies other than what the tutorial linked here advises)
Not sure that setting JAVA_HOME env var is viable, I am trying to produce a standalone EXE for users without JDK/JRE installed
tlf30 commentedon Aug 26, 2023
Please see my note above: #3659 (comment)
No need to have the jvm, just a couple files from it along side the exe.
Still, I am amazed that this has not been fixed by the graalvm team, it just shows how immature graalvm is still.
lyjia commentedon Aug 26, 2023
Indeed. I had to translate your gradle fragment to maven and I think I may have gotten it working, but my native EXE is now throwing tons of
java.lang.Error: no ComponentUI class
for every Swing component I am using and the UI does not draw. I haven't had a chance to look into why yet.In case it is useful to anyone else, the maven script is (put this in the
<build>
section of your 'native-image' profile):zlbProject commentedon Jan 31, 2024
‘graalvm.groupId’ and ‘graalvm.version’ what is it?