title: GluonFX, native image for windows and CDI
body: <p>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).</p>
  <p>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.</p>
  <p>In my build process I always execute &quot;mvn gluonfx:runagent&quot;. This helped to solve a couple of</p>
  <p>&quot;<code>could not resolved &lt;type&gt; for reflection configuration</code>&quot;</p>
  <p>issues in a semi-automatic way. Unfortunately it did not solve all of them.</p>
  <p>I managed to solve some further cases by explicitely loading some types with <code>Class.forName(...)</code>. But I still did not catch all cases successfully. However, I noticed that among the remaining types there are</p>
  <ul>
  <li><code>jakarta.enterprise.event.Event</code> and</li>
  <li><code>jakarta.enterprise.inject.Instance</code></li>
  </ul>
  <p>or to be more precise</p>
  <ul>
  <li><code>jakarta.enterprise.event.Event$WeldEvent$Proxy$_$$_Weld$Proxy$</code> and</li>
  <li><code>jakarta.enterprise.inject.Instance$Provider$WeldInstance$Proxy$_$$_Weld$Proxy$</code>.</li>
  </ul>
  <p>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 &quot;loaded&quot; the types explicitely with <code>CDI.select(...)</code>. Does anybody have an idea of how to proceed from here?</p>
  <p>Environment:</p>
  <ul>
  <li>Windows 10 / 11</li>
  <li>Visual Studio 2022 Developer Command Prompt v17.0.6</li>
  <li>OpenJDK Runtime Environment GraalVM CE 22.0.0.2 (build 17.0.2+8-jvmci-22.0-b05)</li>
  </ul>
  <p>Please let me know if I can provide further information.</p>
  <p><strong>edit 1:</strong></p>
  <p>I forgot to mention that a native executable (.exe) can be created successfully. Unfortunately the .exe file does not start the application.</p>
  <p><strong>edit 2:</strong></p>
  <p>I just tried <code>mvn gluon:nativerun</code>. I guess that starts the .exe file and prints out some logging and stuff. Is that correct?</p>
  <p>However in the logging I can see that weld finds six <code>META-INF/beans.xml</code> files and complains:</p>
  <p><code>Exception in thread &quot;main&quot; java.lang.IllegalStateException: WELD-ENV-000033: Invalid bean archive scanning result - found multiple results with the same reference: resource:META-INF/beans.xml</code></p>
  <p>I can see that five custom .jar files I depend on contain <code>META-INF/beans.xml</code> files. They are copied to</p>
  <p><code>target\gluonfx\x86_64-windows\gvm\tmp\deps</code></p>
  <p>by <code>gluonfx:compile</code>. What am I supposed to do about duplicate <code>beans.xml</code> files? BTW: duplicate <code>beans.xml</code> files are no problem when running the app in the JVM.</p>
  <p><strong>edit 3:</strong></p>
  <p>I created a small reproducer that can be found <a href="https://github.com/r-uu/sandbox-gluonfx-cdi" rel="nofollow noreferrer">here</a>. It is a multi-module maven project. <code>main</code> module defines a small javafx app that depends on <code>lib1</code> and <code>lib2</code>. The <code>lib</code> modules are empty except from a <code>META-INF/beans.xml</code> inside each of them.</p>
  <p>The <code>.exe</code> file is created but does nothing if invoked directly. When invoked via <code>gluonfx:nativerun</code> the log output is like this:</p>
  <pre><code>[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 &quot;main&quot; 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)
  </code></pre>