dustinkredmond / FXTrayIcon

Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.
MIT License
334 stars 26 forks source link

Add graalvm-native image support! #88

Open ctoabidmaqbool opened 3 months ago

ctoabidmaqbool commented 3 months ago

Can FXTrayIcon be used in GraalVM-Native Image?

I think still FXTrayIcon is dependent upon AWT or Swing Part! It can't be used in Grallvm native-image feature.

Actually I have a project which is based upon Javafx and Gluonfx Plugins which behind the scene uses graalvm native-image feature If someone try to build native-image.

In my app also i need to add system tryicon too!

dustinkredmond commented 3 months ago

We're 100% reliant on AWT, so if that's something that doesn't mesh with GraalVM, I doubt we'd ever be able to support it. This library basically just wraps the AWT calls in a way that's intuitive for JavaFX developers.

ctoabidmaqbool1 commented 3 months ago

AWT or SWING is not supported yet on GraalVM native-image feature, but In another project e.g. icepdf after adding awt.dll, java.dll and jvm.dll I was able to secessfully run native-image executable.

But in case of this project, still I am facing issues!

D:\JavaFx-Android\gluon-samples-gradle>gradlew :FXTrayIcon:nativeRun
Starting a Gradle Daemon, 1 busy and 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
[Wed Aug 07 08:12:06 PKT 2024][INFO] [SUB] Aug 07, 2024 8:12:06 AM com.sun.javafx.application.PlatformImpl startup
[Wed Aug 07 08:12:06 PKT 2024][INFO] [SUB] WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @6b71769e'
[Wed Aug 07 08:12:07 PKT 2024][INFO] [SUB] Exception in thread "AWT-Windows": java.lang.ClassCastException
[Wed Aug 07 08:12:07 PKT 2024][INFO] [SUB] java.lang.ClassCastException: [no exception stack trace available because exception is thrown from code that must be allocation free]

> Task :FXTrayIcon:nativeRun
[Wed Aug 07 08:12:05 PKT 2024][INFO] ==================== RUN TASK ====================
[Wed Aug 07 08:12:10 PKT 2024][SEVERE] Process run until end failed with result: -1073741819
Check the log files under D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\gluonfx\x86_64-windows\gvm\log
And please check https://docs.gluonhq.com/ for more information.
[Wed Aug 07 08:12:10 PKT 2024][INFO] Logging process [run until end] to file: D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\gluonfx\log\process-run until end-1723000330575.log
 _______  ___      __   __  _______  __    _ 
|       ||   |    |  | |  ||       ||  |  | |
|    ___||   |    |  | |  ||   _   ||   |_| |
|   | __ |   |    |  |_|  ||  | |  ||       |
|   ||  ||   |___ |       ||  |_|  ||  _    |
|   |_| ||       ||       ||       || | |   |
|_______||_______||_______||_______||_|  |__|

https://gluonhq.com/activate

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.7/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.      

BUILD SUCCESSFUL in 1m 13s
3 actionable tasks: 1 executed, 2 up-to-date
D:\JavaFx-Android\gluon-samples-gradle>                                                                                           

process-run until end-1723000330575.log | client-debug0.log

Steps to reproduce it:

  1. Check-out gluon-samples or gluon-samples-gradle
  2. Implement FXTrayIcon project using sample template RunnableTest.java
  3. Before runnin native build tasks run native run agent task and test whole project with all possibilities. e.g. gradlew :FXTrayIcon:nativeRunAgent
  4. Then natice build and native run the project e.g. gradlew :FXTrayIcon:clean :FXTrayIcon:nativeBuild :FXTrayIcon:nativeRun
EasyG0ing1 commented 2 months ago

@ctoabidmaqbool

I've had success with AWT in Java making native-images when I create a FAT JAR file using the Maven Assembly Plugin. I then run the fat jar doing something like this:

java --enable-preview -agentlib:native-image-agent=config-merge-dir=/Users/michael/java/project/graalvm -jar /Users/michael/java/project/target/projectname-jar-with-dependencies.jar

Then you engage the program everywhere it makes calls to AWT that way the libraries are included in the reflect-config.json file. You can also manually add libraries into that file following the syntax. Once those json files are correct, when you make the native image, you point to the source of those json files during the native-image compile phase:

-H:JNIConfigurationFiles=/Users/michael/java/project/graalvm/jni-config.json
-H:DynamicProxyConfigurationFiles=/Users/michael/java/project/graalvm/proxy-config.json
-H:ReflectionConfigurationFiles=/Users/michael/java/project/graalvm/reflect-config.json
-H:ResourceConfigurationFiles=/Users/michael/java/project/graalvm/resource-config.json
-H:SerializationConfigurationFiles=/Users/michael/java/project/graalvm/serialization-config.json

I have several programs that use FXTrayIcon compiled into native-images.

If you need any example POM file configs, let me know.

Mike

ctoabidmaqbool commented 2 months ago

@EasyG0ing1 Thanks!

Can you provide me more info! Maybe runnabe complete example or some parts! I am still failing do to so!

ctoabidmaqbool commented 2 months ago

I have tried another one, but still issues and issues:

D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs>FXTrayIconNative.exe
Sep 18, 2024 11:59:43 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @4e48462d'
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
        at java.base@23/java.lang.Thread.runWith(Thread.java:1588)
        at java.base@23/java.lang.Thread.run(Thread.java:1575)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:832)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:808)
Caused by: java.lang.NoSuchMethodError: sun.awt.windows.WTrayIconPeer.updateImage()V
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1851)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1836)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetMethodID(JNIFunctions.java:443)
        at java.desktop@23/java.awt.TrayIcon.initIDs(Native Method)
        at java.desktop@23/java.awt.TrayIcon.<clinit>(TrayIcon.java:133)
        at com.dustinredmond.fxtrayicon.Restricted.<init>(Restricted.java:43)
        at com.dustinredmond.fxtrayicon.FXTrayIcon.<init>(FXTrayIcon.java:283)
        at com.dustinredmond.fxtrayicon.FXTrayIcon.<init>(FXTrayIcon.java:184)
        at com.dustinredmond.fxtrayicon.RunnableTest.start(RunnableTest.java:61)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
        at java.base@23/java.security.AccessController.executePrivileged(AccessController.java:132)
        at java.base@23/java.security.AccessController.doPrivileged(AccessController.java:400)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
        ... 4 more

the building process:

D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs>native-image --no-fallback -H:JNIConfigurationFiles=graalvm/jni-config.json -H:DynamicProxyConfigurationFiles=graalvm/proxy-config.json -H:ReflectionConfigurationFiles=graalvm/reflect-config.json -H:ResourceConfigurationFiles=graalvm/resource-config.json -H:SerializationConfigurationFiles=graalvm/serialization-config.json -jar FXTrayIcon.jar FXTrayIconNative
Warning: The option '-H:SerializationConfigurationFiles=graalvm/serialization-config.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:DynamicProxyConfigurationFiles=graalvm/proxy-config.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ReflectionConfigurationFiles=graalvm/reflect-config.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:JNIConfigurationFiles=graalvm/jni-config.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: The option '-H:ResourceConfigurationFiles=graalvm/resource-config.json' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: Please re-evaluate whether any experimental option is required, and either remove or unlock it. The build output lists all active experimental options, including where they come from and possible alternatives. If you think an experimental option should be considered as stable, please file an issue.
Warning: Option 'DynamicProxyConfigurationFiles' is deprecated and might be removed in a future release. Please refer to the GraalVM release notes.
Warning: Option 'DynamicProxyConfigurationResources' is deprecated and might be removed in a future release: This can be caused by a proxy-config.json file in your META-INF directory. Consider including proxy configuration in the reflection section of reachability-metadata.md instead.. Please refer to the GraalVM release notes.
========================================================================================================================
GraalVM Native Image: Generating 'FXTrayIconNative' (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...                                                                                   (16.9s @ 0.12GB)
 Java version: 23+37, vendor version: GraalVM CE 23+37.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
------------------------------------------------------------------------------------------------------------------------
 5 experimental option(s) unlocked:
 - '-H:ReflectionConfigurationFiles': Use a reflect-config.json in your META-INF/native-image/<groupID>/<artifactID> directory instead. (origin(s): command line)
 - '-H:ResourceConfigurationFiles': Use a resource-config.json in your META-INF/native-image/<groupID>/<artifactID> directory instead. (origin(s): command line)
 - '-H:DynamicProxyConfigurationFiles': Use a proxy-config.json in your META-INF/native-image/<groupID>/<artifactID> directory instead. (origin(s): command line)
 - '-H:JNIConfigurationFiles': Use a jni-config.json in your META-INF/native-image/<groupID>/<artifactID> directory instead. (origin(s): command line)
 - '-H:SerializationConfigurationFiles': Use a serialization-config.json in your META-INF/native-image/<groupID>/<artifactID> directory instead. (origin(s): command line)
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 12.01GB of memory (75.6% of 15.89GB system memory, determined at start)
 - 4 thread(s) (100.0% of 4 available processor(s), determined at start)
[2/8] Performing analysis...  [*****]                                                                  (112.4s @ 1.16GB)
   10,683 reachable types   (83.6% of   12,777 total)
   20,021 reachable fields  (57.6% of   34,743 total)
   55,128 reachable methods (58.7% of   93,953 total)
    3,157 types,    19 fields, and   567 methods registered for reflection
      232 types,   346 fields, and   314 methods registered for JNI access
        3 native libraries: crypt32, ncrypt, version
[3/8] Building universe...                                                                              (17.9s @ 1.32GB)
[4/8] Parsing methods...      [***]                                                                     (11.8s @ 0.78GB)
[5/8] Inlining methods...     [***]                                                                      (9.1s @ 0.90GB)
[6/8] Compiling methods...    [**********]                                                             (108.2s @ 1.37GB)
[7/8] Laying out methods...   [****]                                                                    (12.6s @ 1.72GB)
[8/8] Creating image...       [***]                                                                      (7.8s @ 1.90GB)
  25.53MB (48.34%) for code area:    32,940 compilation units
  26.94MB (51.01%) for image heap:  281,649 objects and 138 resources
 353.19kB ( 0.65%) for other data
  52.81MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 origins of code area:                                Top 10 object types in image heap:
   6.99MB java.desktop                                         6.38MB byte[] for code metadata
   6.93MB java.base                                            3.89MB byte[] for embedded resources
   6.14MB FXTrayIcon.jar                                       3.63MB byte[] for java.lang.String
   2.88MB java.xml                                             2.75MB java.lang.String
   1.48MB svm.jar (Native Image)                               2.61MB java.lang.Class
 147.23kB jdk.jfr                                            918.07kB com.oracle.svm.core.hub.DynamicHubCompanion
 119.93kB java.logging                                       570.60kB byte[] for reflection metadata
 113.92kB jdk.proxy1                                         561.17kB java.lang.String[]
 109.72kB java.datatransfer                                  513.05kB int[][]
  71.28kB java.prefs                                         480.20kB byte[] for general heap data
 321.48kB for 12 more packages                                 4.71MB for 2057 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.
------------------------------------------------------------------------------------------------------------------------
                       14.8s (4.8% of total time) in 1948 GCs | Peak RSS: 2.45GB | CPU load: 2.38
------------------------------------------------------------------------------------------------------------------------
Build artifacts:
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\awt.dll (jdk_library)
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\fontmanager.dll (jdk_library)
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\freetype.dll (jdk_library)
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\FXTrayIconNative.exe (executable)
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\java.dll (jdk_library_shim)
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\javaaccessbridge.dll (jdk_library)
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\javajpeg.dll (jdk_library)
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\jawt.dll (jdk_library)
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\jvm.dll (jdk_library_shim)
 D:\JavaFx-Android\gluon-samples-gradle\FXTrayIcon\build\libs\lcms.dll (jdk_library)
========================================================================================================================
Finished generating 'FXTrayIconNative' in 5m 3s.
EasyG0ing1 commented 2 months ago

@ctoabidmaqbool

Here is the POM file for an app I wrote for myself that uses only FXTrayIcon as the interface with some JavaFX screens that pop out from some menu selections:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.simtechdata</groupId>
    <artifactId>SimpleOTP</artifactId>
    <version>1.0</version>
    <name>SimpleOTP</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <javafx.version>22</javafx.version>
        <source.target.release>22</source.target.release>
        <maven-compiler-plugin>3.13.0</maven-compiler-plugin>
        <maven-jar-plugin>3.4.2</maven-jar-plugin>
        <maven-enforcer-plugin>3.5.0</maven-enforcer-plugin>
        <maven-assembly-plugin>3.7.1</maven-assembly-plugin>
        <maven-dependency-plugin>3.8.0</maven-dependency-plugin>
        <exec-maven-plugin>3.2.0</exec-maven-plugin>
        <exec.domain>com.simtechdata</exec.domain>
        <mainClass>com.simtechdata.Main</mainClass>
        <javapackager>1.7.5</javapackager>
        <gluonfx-maven-plugin>1.0.22</gluonfx-maven-plugin>
        <javafx-maven-plugin>0.0.8</javafx-maven-plugin>
        <gluonfx.target>22</gluonfx.target>
        <moditect-maven-plugin>1.2.1.Final</moditect-maven-plugin>
        <versions-maven-plugin>2.17.1</versions-maven-plugin>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>com.simtechdata</groupId>
            <artifactId>EasyFXControls</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>com.simtechdata</groupId>
            <artifactId>GoogleAuthDecoder</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>com.simtechdata</groupId>
            <artifactId>OTPURI</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>1.9.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-crypto</artifactId>
            <version>6.3.3</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.17.0</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.13.0</version>
        </dependency>
        <dependency>
            <groupId>com.dustinredmond.fxtrayicon</groupId>
            <artifactId>FXTrayIcon</artifactId>
            <version>4.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>3.5.3</version>
        </dependency>
        <dependency>
            <groupId>com.google.crypto.tink</groupId>
            <artifactId>tink</artifactId>
            <version>1.15.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-text</artifactId>
            <version>1.12.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>javase</artifactId>
            <version>3.5.3</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.hildan.fxgson</groupId>
            <artifactId>fx-gson</artifactId>
            <version>5.0.0</version>
        </dependency>
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>5.15.0</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>Gluon</id>
            <url>https://nexus.gluonhq.com/nexus/content/repositories/releases</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <!--Maven Versions-->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>${versions-maven-plugin}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>display-dependency-updates</goal>
                            <goal>display-plugin-updates</goal>
                            <goal>property-updates-report</goal>
                            <goal>dependency-updates-report</goal>
                            <goal>plugin-updates-report</goal>
                            <goal>update-properties</goal>
                            <goal>use-latest-versions</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--Maven Enforcer Plugin-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>${maven-enforcer-plugin}</version>
                <executions>
                    <execution>
                        <id>enforce-maven</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>4.0.0-beta-3</version>
                                </requireMavenVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!--Maven Compiler-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin}</version>
                <configuration>
                    <source>${source.target.release}</source>
                    <target>${source.target.release}</target>
                    <compilerArgs>--enable-preview</compilerArgs>
                </configuration>
            </plugin>
            <!--Maven Jar-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven-jar-plugin}</version>
                <configuration>
                    <skipIfEmpty>true</skipIfEmpty>
                    <archive>
                        <manifestEntries>
                            <Main-Class>${mainClass}</Main-Class>
                            <Automatic-Module-Name>${artifactId}</Automatic-Module-Name>
                            <Program-Version>${project.version}</Program-Version>
                            <Implementation-Version>${project.version}</Implementation-Version>
                        </manifestEntries>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>${mainClass}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <!--Maven Dependency Plugin - for collecting modules-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>${maven-dependency-plugin}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/modules</outputDirectory>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

And here are the scripts that I use to create the native image:

First, this script creates all of the necessary json files for the native-image build:

#!/bin/bash

JP="$HOME/JetBrainsProjects/IntelliJIdea/SimpleOTP"
G="$JP/graalvm"
T="$JP/target"

mvn -f $JP/pom.xml clean
mvn -f $JP/pom.xml install

java \
--enable-preview \
-agentlib:native-image-agent=config-merge-dir=$G \
--module-path $T/SimpleOTP-1.0.jar:$T/modules \
-m SimpleOTP/com.simtechdata.Main graalvm

java --enable-preview --module-path target/SimpleOTP-1.0.jar:target/modules -m SimpleOTP/com.simtechdata.Main

When I run that script, I engage the program and all of the features that implement the various calls so that they get included in the json files. The Maven Dependency Plugin creates a folder in target that contains all of the dependency libraries that the program uses, which I include in the running of the jar file using the --module-path argument.

Next, I compile the native image like this:

#!/bin/bash

JP=$HOME/JetBrainsProjects/IntelliJIdea/SimpleOTP
G=$JP/graalvm
T=$JP/target

mvn -f $JP/pom.xml clean install
echo "Running native-image"
native-image \
--no-fallback \
--verbose \
--enable-preview \
--module-path $T/SimpleOTP-1.0.jar:$T/modules:$HOME/.m2/repository/org/xerial/sqlite-jdbc/3.45.3.0/sqlite-jdbc-3.45.3.0.jar \
--module SimpleOTP/com.simtechdata.Main \
--initialize-at-build-time=org.sqlite.util.ProcessRunner \
-H:+UnlockExperimentalVMOptions \
-H:+ReportExceptionStackTraces \
-H:JNIConfigurationFiles=$G/jni-config.json \
-H:DynamicProxyConfigurationFiles=$G/proxy-config.json \
-H:ReflectionConfigurationFiles=$G/reflect-config.json \
-H:ResourceConfigurationFiles=$G/resource-config.json \
-H:SerializationConfigurationFiles=$G/serialization-config.json \
-H:Name=$T/SimpleOTP

cp $T/SimpleOTP $HOME/JavaBASH/

I hope that helps...

Mike

ctoabidmaqbool commented 2 months ago

@EasyG0ing1 Thanks your provided solutions works like a charm https://github.com/ctoabidmaqbool/SimpleOTP

I have a little issue now!

On my Windows 10, using run or run-agent, all is working correctly!

java --enable-preview -agentlib:native-image-agent=config-merge-dir="%G%" --module-path "%T%\SimpleOTP-1.0.jar;%T%\modules" -m SimpleOTP/com.simtechdata.Main graalvm

Or

java --enable-preview --module-path "%T%\SimpleOTP-1.0.jar;%T%\modules" -m SimpleOTP/com.simtechdata.Main

image

But in the case of native-image .exe TrayIconFx drop-down menu show nothing~

%T%\SimpleOTP.exe

image

@EasyG0ing1 Any idea how to solve it?

ctoabidmaqbool commented 2 months ago

I also be able to use simple java Swing/SWT tryicon in Graalvm native-image runiing~ https://github.com/ctoabidmaqbool/SimpleOTP/tree/system_tray_icon

But still a little bit of issue!

when running native-image .exe %T%\SimpleOTP.exe after buiding, drop-down cut-off: image

but javafx running or run-agent runing no issue at all!

java --enable-preview --module-path "%T%\SimpleOTP-1.0.jar;%T%\modules" -m SimpleOTP/com.simtechdata.Main

image