java - maven 使用 --add-exports 运行和构建

标签 java maven javafx controlsfx openfx

我尝试在 Win 10 机器上使用 InteliJ 和 Maven 运行我的应用程序。
如果我跑

mvn clean javafx:run

我的 GUI 启动,但如果我使用 org.controlsfx.control.textfield.TextFields 中的 Textfield
我遇到了一个问题
Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class org.controlsfx.control.textfield.AutoCompletionBinding (in unnamed module @0x19b440d0) cannot access class com.sun.javafx.event.EventHandlerManager (in module javafx.base) because module javafx.base does not export com.sun.javafx.event to unnamed module @0x19b440d0

我发现这是一个已知问题,您必须按照命令传递给 JVM。
--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls

但是我如何在 Maven 中做到这一点?
我尝试了 2 种方法。

方式一:
使用 .mvn/jvm.config 文件并添加这个命令,但这根本不会改变任何东西,即使在那里输入无意义的东西。

方式二:
使用 --add-export 命令添加系统变量 MAVEN_OPTS。
然后 maven 对这个变化使用react,但说:
WARNING: Unknown module: org.controlsfx.controls specified to --add-exports

我该如何解决这个问题?

编辑:方式三:
根据 https://github.com/openjfx/javafx-maven-plugin应该可以将这个 --add-export 添加到 javafx-maven-plugin 中,但是 InteliJ 将其标记为无效,该元素不能在这个地方使用
<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.4</version>
    <configuration>
        <compilerArgs>
            <arg>--add-exports</arg>
            <arg>javafx.graphics/com.sun.glass.ui=org.openjfx.hellofx</arg>
        </compilerArgs>
        <mainClass>org.openjfx.hellofx/org.openjfx.App</mainClass>
    </configuration>
</plugin>

https://github.com/openjfx/javafx-maven-plugin/issues/53似乎已知但不被视为问题

最佳答案

对于发现此问题的任何人,javaFX 插件不再支持方式 3 中所述的编译器选项。
您必须将 args 添加到编译器插件中,如下所示:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.1</version>
      <configuration>
        <compilerArgs>
          <arg>--add-exports</arg>
          <arg>java.management/sun.management=ALL-UNNAMED</arg>
        </compilerArgs>
      </configuration>
    </plugin>
  </plugins>
</build>

关于java - maven 使用 --add-exports 运行和构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61771048/

相关文章:

css - 无法在 Gluon 元素上加载皮肤错误

javafx 由 : java. lang.UnsupportedOperationException 引起

java - 使用数组作为参数

java - 列出和链接文件

java - 在 Eclipse 中手动安装 scala-maven-plugin

java - Maven 原型(prototype)插件未应用所有属性

java - 找出可以用 1 和 0 写成的数的倍数

java - 如何在java中刷新dns

java - Maven: assembly-plugin 根本没有运行

java - 如何从 2 个独立的 JavaFX 服务线程中获取结果?