Intellij中的JavaFX和Maven:设置了JAVA_HOME,但设置了“无法识别的选项--module-path"错误持续存在 [英] JavaFX and Maven in Intellij: JAVA_HOME set but "Unrecognized option --module-path" error persisting

查看:280
本文介绍了Intellij中的JavaFX和Maven:设置了JAVA_HOME,但设置了“无法识别的选项--module-path"错误持续存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using Maven and JavaFX in Intellij (2019.1). I have been following this tutorial.

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

I have a curious error that keeps occurring - every time I keep running the javafx:run plugin, it fails, giving this error:

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的安装位置.

However, when I put the executable in the javafx-maven-plugin (<executable>"C:\Program Files\Java\jdk-12.0.1\bin\java.exe"</executable>) it works. I am on Windows and have set the JAVA_HOME system environment variable to C:\Program Files\Java\jdk-12.0.1 which is where the JDK is installed.

这不是一个关键问题,但很高兴知道答案.

This is a curious issue that is not critical, but would be nice to know the answer to.

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>

其他图片:

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在用户路径中.

Note also that C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.1\bin is in user path.

推荐答案

对于将来的观看者来说,答案非常简单:JavaFX入门时,有关maven的说明与intellij和maven有关(非模块版本). ),在此处中发现是不正确的.

For future viewers, the answer turned out to be very simple: the instructions for maven at the getting started with JavaFX are with intellij and maven (non-module version), as found here are slightly incorrect.

说明如下:

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

You can open the Maven Projects window and click on HelloFX -> Plugins -> compiler -> compiler:compile to compile the project, and click on HelloFX -> Plugins -> javafx -> javafx:run to execute the project.

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

The key part that is wrong here is that if you are using a project that uses static resources - like the FXML files in the HelloFX project - then compiling only using compiler:compile will not copy these files into the target\classes directory.

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

This is a subtle mistake in the guide - presumably because if you build from command line nothing will be wrong - using mvn clean javafx:run will perform all the steps in between. Therefore, the instructions need to be to run compiler:compile and resources:resources for the thing to work in Intellij.

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

Alternatively, the guide could be changed to say just run javafx:compile or run the lifecycle phase called package in intellij, and then run javafx:run.

这篇关于Intellij中的JavaFX和Maven:设置了JAVA_HOME,但设置了“无法识别的选项--module-path"错误持续存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆