Mar*_*986 5 java javafx maven 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 种方法。
方式 1: 使用 .mvn/jvm.config 文件并添加此命令,但这根本不会改变任何东西,即使在那里输入无意义的东西。
方式二:使用 --add-export 命令 添加系统变量MAVEN_OPTS。然后 maven 对这个变化做出反应,但说:
WARNING: Unknown module: org.controlsfx.controls specified to --add-exports
我该如何解决这个问题?
编辑:方式 3: 根据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似乎已知但不被视为问题
小智 16
对于发现此问题的人,javaFX 插件不再支持方式 3 中描述的编译器选项。
您必须将参数添加到编译器插件中,如下所示:
<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>
| 归档时间: | 
 | 
| 查看次数: | 1738 次 | 
| 最近记录: |