9

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?

fabian
  • 80,457
  • 12
  • 86
  • 114
user3785637
  • 119
  • 1
  • 1
  • 6
  • 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. – Aram Becker Nov 19 '17 at 12:11
  • What version of IntelliJ are you using? And what is the error message that you get? – Naman Nov 19 '17 at 18:27

6 Answers6

13

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

y.bedrov
  • 5,318
  • 3
  • 22
  • 19
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

Fuyang Liu
  • 1,496
  • 13
  • 26
  • 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. – Mejmo Aug 21 '18 at 19:39
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.

ThirstyCamel
  • 61
  • 1
  • 4
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.

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
1

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

javafx {
  version = "11"
  modules = [ 'javafx.controls', 'javafx.fxml' ]
}
inetphantom
  • 2,498
  • 4
  • 38
  • 61
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;
hariprasad
  • 555
  • 11
  • 20