簡體   English   中英

maven 使用 --add-exports 運行和構建

[英]maven run and build with --add-exports

我嘗試在 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 中做到這一點? 我嘗試了兩種方法。

方式 1:使用 .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應該可以添加到 javafx-maven-plugin 這個 --add-export 到但 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM