JavaFX does not exist using Java 9 and Intellij Idea
Asked Answered
S

6

10

I am using Intellij Idea to compile a project that uses Maven dependencies and Intellij keeps telling me that my project has 50 something errors because JavaFX does not exist.

Intellij is not highlighting all the javafx dependencies in my code as errors, it is just that once I press the run and compile the program says that everything in JavaFX does not exists.

I tried to redownload the latest JDK (Java 9.0.1) and that did not fix it. I went into the Default Project Structure and Project Structure to make sure it was using the correct jdk and that did not fix the issue. All the jdks I am using seem to list the javafx packages as included in the project.

This is also only an issue for a particular project that I am working on with a friend. We may have to move over all our code into a new project, however I am not sure if that will fix anything.

Any suggestions?

Serra answered 19/11, 2017 at 12:6 Comment(2)
Have you tried compiling it with maven? I had so e issues with javaFX and compiling through intelliJ myself. It works now but I have no idea why.Net
What version of IntelliJ are you using? And what is the error message that you get?Rockey
D
13

Try to set project language level to "9" in "Project Structure | Project"

Deformation answered 20/11, 2017 at 8:48 Comment(1)
I have the same issue, and this seems not helping. Any other idea why?Beene
B
11

Okay I see what my problem was.

Besides Try to set project language level to "9" in "Project Structure | Project" mentioned above, I had a maven setting in some pom.xml looks like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven-compiler-plugin.version}</version>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
    </configuration>
</plugin>

and java.version was defined as 1.8 somewhere above. I just had to change it to 9

Beene answered 20/12, 2017 at 21:49 Comment(1)
And what if I do not want to have 9 as a target? I just want to compile the project so that it can run on both JDK8 and JDK9/10. If I compile it for target 9, it will not work on 1.8.Sigil
T
6

I had this problem after upgrading a JavaFX project from Java 8 to Java 9.

After checking the usual language level settings for the project and module in IntelliJ and the Maven pom, I found the problem was that the module was explicitly set to generate Java 8 bytecode in the Java Compiler preferences.

Look in Preferences -> Build, Execution, Deployment -> Compiler -> Java Compiler. Check that Project bytecode version is unset (or set correctly) and that your module is not listed in Per-module bytecode version with an incorrect value.

Taking answered 12/3, 2018 at 14:5 Comment(0)
R
1
File --> Project Structure-->Module

The language level in here as set to 5 for me. Upped it to 9 to allow classes etc and the same error as described above resolved for me.

Randyranee answered 2/4, 2018 at 8:57 Comment(2)
Did you read the previous answers and comments? What new information is your answer giving?Kegler
Actually helped, since I could not find where Project Structure was locatedHeyde
P
1

I missed the modules in my gradle.build. Had to update

javafx {
  version = "11"
  modules = [ 'javafx.controls', 'javafx.fxml' ]
}
Painless answered 4/5, 2019 at 19:35 Comment(0)
O
0

In Java9+ some modules are not included in JRE/JDK. The solution is to add thore libraries explicitly.

For maven pom file for Java9 I used

<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>11</version>
</dependency>

Than I can use desired libray for including of TextField.

import javafx.scene.control.TextField;
Oxygenate answered 28/5, 2020 at 21:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.