Comments (5)
Hey @zgmgt, Unfortunately, I can't download the project directly due to our internal policy. Would you mind uploading it to a public GitHub repository and sharing the link with me? Thank you!
Hey @selhagani . Okay, I'll just paste them out, just two files.
SwingSample.java
package org.example;
import java.awt.*;
import javax.swing.*;
public class SwingSample {
public static void main(String[] args) throws Exception {
if (System.getProperty("rrr","").equals("")) {
System.setProperty("java.home",".");
}
System.getProperties().list(System.out);
SwingUtilities.invokeAndWait(() -> {
JFrame frame = new JFrame("Hello World");
JButton button = new JButton("Hello");
button.addActionListener(e -> {
System.out.printf("Hello, World!%n");
});
JPanel panel = new JPanel(new FlowLayout());
panel.add(button);
frame.add(panel);
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>jdk21graalvm</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.example.SwingSample</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
from graal.
Hi @zgmgt, thank you for reaching out to us!
I am trying to reproduce the issue but I am getting a different error. Could you please share with me the full pom file you're using? Thank you!
from graal.
Hi @zgmgt, thank you for reaching out to us!
I am trying to reproduce the issue but I am getting a different error. Could you please share with me the full pom file you're using? Thank you!
Hi @selhagani ,thank you for your reply. The attachment is my project file
jdk21graalvm.zip
from graal.
Hey @zgmgt, Unfortunately, I can't download the project directly due to our internal policy. Would you mind uploading it to a public GitHub repository and sharing the link with me? Thank you!
from graal.
Hi @zgmgt, I wanted to share a helpful update regarding the issue you're facing.
When I used the latest version of GraalVM CE which can be found here and I removed this part from the code:
if (System.getProperty("rrr","").equals("")) { System.setProperty("java.home","."); }
Then I ran the command
mvn clean package
Followed up by
java -agentlib:native-image-agent=config-output-dir=./cdir -jar jdk21graalvm-1.0-SNAPSHOT.jar
then I used this command to generate the native image:
native-image -jar jdk21graalvm-1.0-SNAPSHOT.jar -H:+ReportExceptionStackTraces --no-fallback --link-at-build-time -H:ConfigurationFileDirectories=./cdir -H:+AddAllCharsets --report-unsupported-elements-at-runtime --enable-url-protocols=https,http -Djava.awt.headless=false
and then I ran the native image using the following command
./jdk21graalvm-1.0-SNAPSHOT -Djava.home=/home/soufiane/Downloads/graalvm-community-openjdk-22.0.1+8.1
Then it worked correctly.
The issue is attributed to how some AWT/Swing classes are loading required properties from the JVM at runtime by invoking the system.getProperty("java.home") which is not available to native images at runtime.
from graal.
Related Issues (20)
- no error message while having Exception. HOT 3
- GraalJS should support Ahead-of-Time(AOT) compilation to Native binary like GraalPy. HOT 5
- NoClassDefFoundError: com.oracle.svm.core.c.function.CEntryPointNativeFunctions HOT 2
- Native build failed after upgrade graalVM jdk 22 on linux but success on macOS HOT 4
- Error: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: type is not available in this platform: com.oracle.svm.hosted.NativeImageSystemClassLoader HOT 7
- [GR-53978] Class graph unable to load classes with GraalVM JDK21 HOT 12
- Print exception details/stacktrace when failed to add a library HOT 2
- Too heavyweight org.graalvm.shadowed.icu4j HOT 4
- Native Shared Library Unable To List Names of Annotated Class HOT 9
- Runtime reflection is not supported for public javax.ws.rs.core.Response$StatusType org.jboss.resteasy.specimpl.AbstractBuiltResponse.getStatusInfo() HOT 3
- Runtime reflection is not supported for public javax.ws.rs.core.Response$StatusType org.jboss.resteasy.specimpl.AbstractBuiltResponse.getStatusInfo() HOT 3
- Statically Linked native image does not produce/embed all the needed .so next to the executable HOT 2
- Add support for JCMD and the Attach API HOT 6
- How to configure Gradle to initialize specific modules at runtime when generating a native image with GraalVM? HOT 2
- [GR-54108] Polyglot memory leak on simple python execution HOT 1
- [GR-54965] objectInputStream.readObject() issue with springboot 3.3.0 + graalvm22 as native image HOT 15
- Call for Lead Maintainers – GraalVM Backports Repositories HOT 14
- Future proposal: have "javac" directly support graalvm + (static) native image creation HOT 2
- Using native-image and Android apk files. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graal.