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

时间:2019-04-25 18:11:32

标签: java maven intellij-idea javafx

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

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

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --module-path

但是,当我将可执行文件放入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>

其他图片:

Project language level Project outline

环境路径

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

还要注意C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.1\bin在用户路径中。

3 个答案:

答案 0 :(得分:0)

要查看是否已设置JAVA_HOME,请打开cmd提示符:

echo %JAVA_HOME%

如果控制台上没有任何显示,则需要设置该变量,即使PATH变量中已经存在该变量,这也是两个不同的环境变量。

答案 1 :(得分:0)

对于将来的观看者来说,答案非常简单:JavaFX入门中有关maven的说明与intellij和maven(非模块版本)有关,here有点不正确。

说明如下:

  

您可以打开Maven项目窗口,然后单击HelloFX->插件->编译器->编译器:编译以编译该项目,然后单击HelloFX->插件-> javafx-> javafx:run以执行该项目。

这里关键的问题是,如果您使用的项目使用静态资源(例如HelloFX项目中的FXML文件),则仅使用compiler:compile进行编译不会将这些文件复制到{{ 1}}目录。

这是本指南中的一个细微错误-大概是因为,如果您是从命令行构建的,那将是没有错的-使用target\classes将执行这两个步骤之间的所有步骤。因此,指令必须运行mvn clean javafx:runcompiler:compile才能在Intellij中运行。

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

答案 2 :(得分:0)

使用Maven设置JavaFX项目时,我也遇到了类似的麻烦。该命令需要更新版本的JDK,而当前的问题是Maven实际上会忽略您系统的JAVA_HOMEJDK_HOME变量以及您的IDE设置。 / p>

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

$ java -version

对于Windows,您只需将指向新Java版本的条目移到旧Java版本上方,就像这样:

enter image description here