Giter VIP home page Giter VIP logo

Comments (5)

zgmgt avatar zgmgt commented on July 22, 2024 1

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.

selhagani avatar selhagani commented on July 22, 2024

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.

zgmgt avatar zgmgt commented on July 22, 2024

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.

selhagani avatar selhagani commented on July 22, 2024

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.

selhagani avatar selhagani commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.