Skip to content
Advertisement

JavaFX and Maven in Intellij: JAVA_HOME set but “Unrecognized option –module-path” error persisting

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

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

However, when I put the executable in the javafx-maven-plugin (<executable>"C:Program FilesJavajdk-12.0.1binjava.exe"</executable>) it works. I am on Windows and have set the JAVA_HOME system environment variable to C:Program FilesJavajdk-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.

EDIT:

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>

Other pictures:

Project language level Project outline

Environment Path

C:Rtoolsbin
C:Program FilesMicrosoft MPIBin
C:Python37Scripts
C:Python37
C:WINDOWSsystem32
C:WINDOWS
C:WINDOWSSystem32Wbem
C:WINDOWSSystem32WindowsPowerShellv1.0
C:WINDOWSSystem32OpenSSH
C:Program FilesJavajdk-12.0.1bin
C:Program Filesapache-maven-3.6.1bin
C:Program Files (x86)Common FilesOracleJavajavapath
C:ProgramDatachocolateybin
C:Program Files (x86)Bracketscommand
C:Program FilesGitcmd
C:Program Filesdotnet
C:Program FilesMicrosoft SQL Server130ToolsBinn
C:Program FilesPuTTY
C:Program Filesnodejs
C:Program FilesGradlegradle-5.4bin

Note also that C:Program FilesJetBrainsIntelliJ IDEA 2019.1.1bin is in user path.

Advertisement

Answer

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.

The instructions are as follows:

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.

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 targetclasses directory.

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.

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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement