2

I am trying to create a native image for windows for an existing JavaFX application using maven. I have successfully created native images for windows for smaller applications, so the general prerequisites should be ok (see details about my environment below).

This time CDI (weld implementation) comes into play and I am running out of ideas how to solve problems that apparently seem to be related to CDI.

In my build process I always execute "mvn gluonfx:runagent". This helped to solve a couple of

"could not resolved <type> for reflection configuration"

issues in a semi-automatic way. Unfortunately it did not solve all of them.

I managed to solve some further cases by explicitely loading some types with Class.forName(...). But I still did not catch all cases successfully. However, I noticed that among the remaining types there are

  • jakarta.enterprise.event.Event and
  • jakarta.enterprise.inject.Instance

or to be more precise

  • jakarta.enterprise.event.Event$WeldEvent$Proxy$_$$_Weld$Proxy$ and
  • jakarta.enterprise.inject.Instance$Provider$WeldInstance$Proxy$_$$_Weld$Proxy$.

The other types are custom types that observe custom CDI events. So I guess I have a problem with CDI and native image. I also "loaded" the types explicitely with CDI.select(...). Does anybody have an idea of how to proceed from here?

Environment:

  • Windows 10 / 11
  • Visual Studio 2022 Developer Command Prompt v17.0.6
  • OpenJDK Runtime Environment GraalVM CE 22.0.0.2 (build 17.0.2+8-jvmci-22.0-b05)

Please let me know if I can provide further information.

edit 1:

I forgot to mention that a native executable (.exe) can be created successfully. Unfortunately the .exe file does not start the application.

edit 2:

I just tried mvn gluon:nativerun. I guess that starts the .exe file and prints out some logging and stuff. Is that correct?

However in the logging I can see that weld finds six META-INF/beans.xml files and complains:

Exception in thread "main" java.lang.IllegalStateException: WELD-ENV-000033: Invalid bean archive scanning result - found multiple results with the same reference: resource:META-INF/beans.xml

I can see that five custom .jar files I depend on contain META-INF/beans.xml files. They are copied to

target\gluonfx\x86_64-windows\gvm\tmp\deps

by gluonfx:compile. What am I supposed to do about duplicate beans.xml files? BTW: duplicate beans.xml files are no problem when running the app in the JVM.

edit 3:

I created a small reproducer that can be found here. It is a multi-module maven project. main module defines a small javafx app that depends on lib1 and lib2. The lib modules are empty except from a META-INF/beans.xml inside each of them.

The .exe file is created but does nothing if invoked directly. When invoked via gluonfx:nativerun the log output is like this:

[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB] 11:08:01.816 INFO  org.jboss.weld.environment.deployment.discovery.DefaultBeanArchiveScanner.getBeanArchiveReference(116) - Unable to adapt URL: resource:META-INF/beans.xml, using its external form instead
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB] 11:08:01.817 INFO  org.jboss.weld.environment.deployment.discovery.DefaultBeanArchiveScanner.getBeanArchiveReference(116) - Unable to adapt URL: resource:META-INF/beans.xml, using its external form instead
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB] 11:08:01.817 INFO  org.jboss.weld.environment.deployment.discovery.DefaultBeanArchiveScanner.getBeanArchiveReference(116) - Unable to adapt URL: resource:META-INF/beans.xml, using its external form instead
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB] 11:08:01.817 WARN  org.jboss.weld.Bootstrap.performDiscovery(132) - WELD-ENV-000031: The bean archive reference resource:META-INF/beans.xml cannot be handled by any BeanArchiveHandler: [org.jboss.weld.environment.deployment.discovery.FileSystemBeanArchiveHandler@52a59711]
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB] Exception in thread "main" java.lang.IllegalStateException: WELD-ENV-000033: Invalid bean archive scanning result - found multiple results with the same reference: resource:META-INF/beans.xml
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB]      at org.jboss.weld.environment.deployment.discovery.AbstractDiscoveryStrategy.performDiscovery(AbstractDiscoveryStrategy.java:116)
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB]      at org.jboss.weld.environment.se.Weld.createDeployment(Weld.java:966)
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB]      at org.jboss.weld.environment.se.Weld.initialize(Weld.java:787)
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB]      at org.jboss.weld.environment.se.Weld.initialize(Weld.java:176)
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB]      at sandbox.gluonfx.cdi.main.clock.Clock.main(Clock.java:35)
[Do. Mõrz 17 11:08:01 MEZ 2022][INFORMATION] [SUB]      at sandbox.gluonfx.cdi.main.clock.ClockRunner.main(ClockRunner.java:9)
r-uu
  • 423
  • 1
  • 4
  • 18
  • 2
    Can you provide an SSCCE? – José Pereda Mar 16 '22 at 10:50
  • Sorry, it took a little longer than expected to create a simple reproducer. However, [here](https://github.com/r-uu/sandbox-gluonfx-cdi) it is. Please let me know if I can help somehow. – r-uu Mar 17 '22 at 10:39
  • 1
    Okay, I'll have a look when time permits. – José Pereda Mar 17 '22 at 11:18
  • 1
    I can reproduce on Mac. Since there are several `META-INF/bean.xml` files, I renamed some of them. `javafx:run` still runs fine, but `javafx:nativerun` now fails with `Unable to adapt URL: resource:META-INF/beans.xml`. This could also explains why same file names fail: GraalVM changes the `jar` URL protocol (like `file:/path_to/jar_name.jar!META-INF/beans.xml`) with the `resource` protocol (like `resource:META-INF/beans.xml`). This implies that Weld doesn't deal with this `resource` protocol (JavaFX required such change, see for instance https://bugs.openjdk.java.net/browse/JDK-8238755). – José Pereda Mar 19 '22 at 16:51
  • Sounds as if I can not use gluonfx and CDI with Weld? Or do you have any idea for a workaround? – r-uu Mar 19 '22 at 18:50
  • 1
    I can't think of a workaround for this. Weld lacks support of `resource:`, and that's how native image deals with static resources. Maybe you can try Ignite/Micronaut https://github.com/gluonhq/ignite ? – José Pereda Mar 19 '22 at 19:45
  • Thanks a lot for having a look at this!!! Too bad that ignite does not support CDI as dependency injection framework. At least not yet!? Meanwhile I will not be able to use gluonfx / native for my apps because CDI is around everywhere ... – r-uu Mar 20 '22 at 18:00

0 Answers0