I am building a native-image using GraalVM (java11-linux-gluon-22.1.0.1-Final) for a java 11 project. The project was on java 1.8 but after converting it to java 11 for the GraalVM to work the build was successful but after i run the program i get this error:
Exception in thread "main" java.awt.AWTError: Toolkit not found: sun.awt.X11.XToolkit
at java.awt.Toolkit$2.run(Toolkit.java:595)
at java.awt.Toolkit$2.run(Toolkit.java:583)
at java.security.AccessController.executePrivileged(AccessController.java:169)
at java.security.AccessController.doPrivileged(AccessController.java:83)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:582)
at java.awt.Toolkit.getEventQueue(Toolkit.java:1494)
at java.awt.EventQueue.invokeLater(EventQueue.java:1312)
at javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1421)
at com.asd.pos.main.MainClass.main(MainClass.java:28)
Here is the pom.xml file:
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>/home/yousef66/Desktop/pos2.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.gluonhq</groupId>
<artifactId>gluonfx-maven-plugin</artifactId>
<version>1.0.15</version>
<configuration>
<mainClass>com.asd.pos.main.MainClass</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Here is the successful build:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.example:demo12:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for groupId:artifactId:jar should use a variable instead of a hard-coded path /home/yousef66/Desktop/pos2.jar @ line 27, column 25
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------------< org.example:demo12 >-------------------------
[INFO] Building demo12 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- gluonfx-maven-plugin:1.0.15:build (default-cli) @ demo12 ---
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.example:demo12:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for groupId:artifactId:jar should use a variable instead of a hard-coded path /home/yousef66/Desktop/pos2.jar @ line 27, column 25
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------------< org.example:demo12 >-------------------------
[INFO] Building demo12 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> gluonfx-maven-plugin:1.0.15:compile (default-cli) > process-classes @ demo12 >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo12 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo12 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 710 source files to /home/yousef66/Desktop/demo12/target/classes
[WARNING] /home/yousef66/Desktop/demo12/src/main/java/com/asd/pos/ui/dialog/StockAddDialog.java: Some input files use or override a deprecated API.
[WARNING] /home/yousef66/Desktop/demo12/src/main/java/com/asd/pos/ui/dialog/StockAddDialog.java: Recompile with -Xlint:deprecation for details.
[WARNING] /home/yousef66/Desktop/demo12/src/main/java/com/asd/pos/ui/frame/InvoiceWorkListFrame.java: Some input files use unchecked or unsafe operations.
[WARNING] /home/yousef66/Desktop/demo12/src/main/java/com/asd/pos/ui/frame/InvoiceWorkListFrame.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] <<< gluonfx-maven-plugin:1.0.15:compile (default-cli) < process-classes @ demo12 <<<
[INFO]
[INFO]
[INFO] --- gluonfx-maven-plugin:1.0.15:compile (default-cli) @ demo12 ---
[Wed Sep 14 10:25:16 EEST 2022][INFO] ==================== COMPILE TASK ====================
_______ ___ __ __ _______ __ _
| || | | | | || || | | |
| ___|| | | | | || _ || |_| |
| | __ | | | |_| || | | || |
| || || |___ | || |_| || _ |
| |_| || || || || | | |
|_______||_______||_______||_______||_| |__|
Access to the latest docs, tips and tricks and more info on
how to get support? Register your usage of Gluon Substrate now at
https://gluonhq.com/activate
[Wed Sep 14 10:25:17 EEST 2022][INFO] We will now compile your code for x86_64-linux-linux. This may take some time.
[Wed Sep 14 10:25:20 EEST 2022][INFO] [SUB] Warning: Ignoring server-mode native-image argument --no-server.
[Wed Sep 14 10:25:25 EEST 2022][INFO] [SUB] ========================================================================================================================
[Wed Sep 14 10:25:25 EEST 2022][INFO] [SUB] GraalVM Native Image: Generating 'com.asd.pos.main.mainclass' (shared library)...
[Wed Sep 14 10:25:25 EEST 2022][INFO] [SUB] ========================================================================================================================
[Wed Sep 14 10:25:26 EEST 2022][INFO] [SUB] [GluonFeature] enabled for config com.oracle.svm.hosted.FeatureImpl$IsInConfigurationAccessImpl@544e3679
[Wed Sep 14 10:25:27 EEST 2022][INFO] [SUB] GluonFeature enabled in setup com.oracle.svm.hosted.FeatureImpl$DuringSetupAccessImpl@2a7bc16b
[Wed Sep 14 10:25:28 EEST 2022][INFO] [SUB] [1/7] Initializing... (7.9s @ 0.21GB)
[Wed Sep 14 10:25:28 EEST 2022][INFO] [SUB] Version info: 'GraalVM 22.1.0.1 Java 11 CE'
[Wed Sep 14 10:25:28 EEST 2022][INFO] [SUB] C compiler: gcc (linux, x86_64, 9.4.0)
[Wed Sep 14 10:25:28 EEST 2022][INFO] [SUB] Garbage collector: Serial GC
[Wed Sep 14 10:25:28 EEST 2022][INFO] [SUB] 1 user-provided feature(s)
[Wed Sep 14 10:25:28 EEST 2022][INFO] [SUB] - com.gluonhq.substrate.feature.GluonFeature
[Wed Sep 14 10:26:52 EEST 2022][INFO] [SUB] [2/7] Performing analysis... [*********] (82.8s @ 4.77GB)
[Wed Sep 14 10:26:52 EEST 2022][INFO] [SUB] 20,249 (90.12%) of 22,468 classes reachable
[Wed Sep 14 10:26:52 EEST 2022][INFO] [SUB] 48,519 (72.63%) of 66,803 fields reachable
[Wed Sep 14 10:26:52 EEST 2022][INFO] [SUB] 109,347 (59.16%) of 184,835 methods reachable
[Wed Sep 14 10:26:52 EEST 2022][INFO] [SUB] 658 classes, 13 fields, and 2,380 methods registered for reflection
[Wed Sep 14 10:26:52 EEST 2022][INFO] [SUB] 119 classes, 159 fields, and 184 methods registered for JNI access
[Wed Sep 14 10:27:06 EEST 2022][INFO] [SUB] [3/7] Building universe... (14.1s @ 4.20GB)
[Wed Sep 14 10:27:11 EEST 2022][INFO] [SUB] [4/7] Parsing methods... [***] (5.1s @ 5.20GB)
[Wed Sep 14 10:27:25 EEST 2022][INFO] [SUB] [5/7] Inlining methods... [******] (13.5s @ 2.31GB)
[Wed Sep 14 10:28:09 EEST 2022][INFO] [SUB] [6/7] Compiling methods... [******] (43.7s @ 4.15GB)
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB]
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] ------------------------------------------------------------------------------------------------------------------------
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] 35.0s (19.2% of total time) in 88 GCs | Peak RSS: 9.44GB | CPU load: 6.15
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] ------------------------------------------------------------------------------------------------------------------------
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] Produced artifacts:
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] /home/yousef66/Desktop/demo12/target/gluonfx/x86_64-linux/gvm/demo12/graal_isolate.h (header)
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] /home/yousef66/Desktop/demo12/target/gluonfx/x86_64-linux/gvm/demo12/com.asd.pos.main.mainclass.h (header)
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] /home/yousef66/Desktop/demo12/target/gluonfx/x86_64-linux/gvm/demo12/graal_isolate_dynamic.h (header)
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] /home/yousef66/Desktop/demo12/target/gluonfx/x86_64-linux/gvm/demo12/com.asd.pos.main.mainclass_dynamic.h (header)
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] /home/yousef66/Desktop/demo12/target/gluonfx/x86_64-linux/gvm/demo12/com.asd.pos.main.mainclass.build_artifacts.txt
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] ========================================================================================================================
[Wed Sep 14 10:28:22 EEST 2022][INFO] [SUB] Finished generating 'com.asd.pos.main.mainclass' in 3m 0s.
[INFO]
[INFO] --- gluonfx-maven-plugin:1.0.15:link (default-cli) @ demo12 ---
[Wed Sep 14 10:28:22 EEST 2022][INFO] ==================== LINK TASK ====================
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:16 min
[INFO] Finished at: 2022-09-14T10:28:24+03:00
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:18 min
[INFO] Finished at: 2022-09-14T10:28:24+03:00
[INFO] ------------------------------------------------------------------------