我尝试在 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/