【问题标题】:maven run and build with --add-exportsmaven 使用 --add-exports 运行和构建
【发布时间】:2020-05-13 09:32:24
【问题描述】:

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

mvn clean javafx:run

我的 GUI 启动,但如果我使用 org.controlsfx.control.textfield.TextFields 中的文本字段 我遇到了问题

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 中做到这一点? 我尝试了两种方法。

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

方式2: 使用 --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 似乎已知但不被视为问题

【问题讨论】:

    标签: java maven javafx controlsfx openfx


    【解决方案1】:

    对于发现此问题的任何人,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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-04
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 2011-01-02
      • 1970-01-01
      相关资源
      最近更新 更多