Intellij 中的 JavaFX 和 Maven:JAVA_HOME 设置但“无法识别的选项 --module-path”错误仍然存​​在

Har*_*lis 4 java javafx intellij-idea maven module-path

在 Intellij 中使用 Maven 和 JavaFX (2019.1)。我一直在关注这个教程。

我有一个不断发生的奇怪错误 - 每次我继续运行插件时javafx:run,它都会失败,并给出以下错误:

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --module-path
Run Code Online (Sandbox Code Playgroud)

但是,当我将可执行文件放入javafx-maven-plugin( <executable>"C:\Program Files\Java\jdk-12.0.1\bin\java.exe"</executable>) 中时,它就可以工作。我在 Windows 上,并已将JAVA_HOME系统环境变量设置为C:\Program Files\Java\jdk-12.0.1安装 JDK 的位置。

这是一个奇怪的问题,虽然并不重要,但很高兴知道答案。

编辑:

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>uk.co.harveyellis</groupId>
    <artifactId>HelloFX</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>12</maven.compiler.source>
        <maven.compiler.target>12</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.2</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>12</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.2</version>
                <configuration>
                    <mainClass>uk.co.harveyellis.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

其他图片:

项目语言水平 项目概要

环境路径

C:\Rtools\bin
C:\Program Files\Microsoft MPI\Bin\
C:\Python37\Scripts\
C:\Python37\
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files\Java\jdk-12.0.1\bin
C:\Program Files\apache-maven-3.6.1\bin
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\ProgramData\chocolatey\bin
C:\Program Files (x86)\Brackets\command
C:\Program Files\Git\cmd
C:\Program Files\dotnet\
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files\PuTTY\
C:\Program Files\nodejs\
C:\Program Files\Gradle\gradle-5.4\bin
Run Code Online (Sandbox Code Playgroud)

另请注意,它C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.1\bin位于用户路径中。

Har*_*lis 6

对于未来的观众来说,答案非常简单:JavaFX 入门时的 maven 说明是使用 intellij 和 maven(非模块版本),如此处发现略有不正确。

说明如下:

您可以打开 Maven Projects 窗口,点击 HelloFX -> Plugins -> compiler -> compiler:compile 来编译项目,然后点击 HelloFX -> Plugins -> javafx -> javafx:ru​​n 来执行项目。

这里错误的关键部分是,如果您使用的项目使用静态资源(例如 HelloFX 项目中的 FXML 文件),则仅编译 usingcompiler:compile不会将这些文件复制到target\classes目录中。

这是指南中的一个微妙错误 - 大概是因为如果您从命令行构建,则不会有任何错误 - usingmvn clean javafx:run将执行其间的所有步骤。因此,指令需要在 Intellij 中运行compiler:compileresources:resources运行。

或者,可以将指南更改为仅运行javafx:compile或运行 intellij 中调用的生命周期阶段package,然后运行javafx:run


J. *_*lus 5

我在使用 Maven 设置 JavaFX 项目时也经历过类似的痛苦。该命令需要较新版本的 JDK,而当前的问题是 Maven 实际上会忽略您的系统JAVA_HOMEJDK_HOME变量,以及您的 IDE 设置。

您只需在控制台中执行以下命令即可检查 Maven 使用的 Java 版本:

$ java -version
Run Code Online (Sandbox Code Playgroud)

对于 Windows,您只需将指向较新 Java 版本的条目移至旧版本之上,如下所示:

在此输入图像描述