GluonFX,Windows 和 CDI 的本机映像

发布于 2025-01-14 19:41:58 字数 4214 浏览 5 评论 0原文

我正在尝试使用 Maven 为现有 JavaFX 应用程序创建 Windows 本机映像。我已经成功为较小的应用程序创建了 Windows 原生映像,因此一般先决条件应该没问题(请参阅下面有关我的环境的详细信息)。

这次 CDI(焊接实现)开始发挥作用,我已经没有办法解决显然与 CDI 相关的问题了。

在我的构建过程中,我总是执行“mvn gluonfx:ru​​nagent”。 解决几个

无法解析反射配置的

这有助于以半自动方式 问题。不幸的是它并没有解决所有问题。

我设法通过使用 Class.forName(...) 显式加载某些类型来解决一些进一步的情况。但我还是没有成功抓到所有案例。但是,我注意到其余类型中有

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

或更准确地说是

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

其他类型是观察自定义 CDI 事件的自定义类型。所以我想我对 CDI 和本机映像有问题。我还使用 CDI.select(...) 显式“加载”类型。有人知道如何从这里开始吗?

环境:

  • Windows 10 / 11
  • Visual Studio 2022 开发人员命令提示符 v17.0.6
  • OpenJDK 运行时环境 GraalVM CE 22.0.0.2(内部版本 17.0.2+8-jvmci-22.0-b05)

如果我可以提供更多信息,请告诉我。

编辑1:

我忘了提及可以成功创建本机可执行文件(.exe)。不幸的是,.exe 文件无法启动应用程序。

编辑2:

我刚刚尝试了mvn gluon:nativerun。我想这会启动 .exe 文件并打印出一些日志记录和内容。这是正确的吗?

然而,在日志记录中,我可以看到焊接找到了六个 META-INF/beans.xml 文件并抱怨:

线程“main”java.lang.IllegalStateException中的异常:WELD-ENV-000033:无效的 bean 存档扫描结果 - 找到具有相同引用的多个结果:resource:META-INF/beans.xml

我可以看到我依赖的五个自定义 .jar 文件包含META-INF/beans.xml 文件。 复制到

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

它们被 gluonfx:compile 。对于重复的 beans.xml 文件我该怎么办?顺便说一句:在 JVM 中运行应用程序时,重复的 beans.xml 文件没有问题。

编辑3:

我创建了一个小型重现器,可以在此处找到。这是一个多模块 Maven 项目。 main 模块定义了一个依赖于 lib1lib2 的小型 javafx 应用程序。除了每个模块内部的 META-INF/beans.xml 之外,lib 模块都是空的。

.exe 文件已创建,但如果直接调用则不会执行任何操作。当通过 gluonfx:nativerun 调用时,日志输出如下所示:

[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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文