问题
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 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.
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:
Environment Path
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
Note also that C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.1\bin
is in user path.
回答1:
I've been experiencing similar pains with setting up a JavaFX project with Maven. That command requires a newer version of the JDK and the issue at hand is that Maven will actually ignore your system's JAVA_HOME
and JDK_HOME
variables, as well as your IDE settings.
You can check which version of Java that Maven is using by simply executing this command in your console:
$ java -version
In the case of Windows, you just move the entry pointing to the newer Java version above the older one, like so:
回答2:
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 target\classes
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
.
回答3:
To see if you have JAVA_HOME set open cmd prompt:
echo %JAVA_HOME%
If nothing prints on the console, you need to set that variable, even if is already on the PATH variable, those are two different environment variables.
来源:https://stackoverflow.com/questions/55855335/javafx-and-maven-in-intellij-java-home-set-but-unrecognized-option-module-pa