cannot resolve symbol javafx.application in IntelliJ Idea IDE

JavaIntellij IdeaJavafx

Java Problem Overview


I tried to create a JavaFX application in IntelliJ Idea IDE but I got compile error that said:

> java: package javafx.application does not exist.

I have changed the Project SDK and the Project Language Level to Java 8, reloaded the project but it didn't help. Then I checked if JavaFX plugin was enabled in the settings.

The search on Google and StackOverflow didn't give me more ideas of what is wrong. Thank for any help in advance.

P.S. I am using IntelliJ Idea 14.0 with java8.1.0_25 on archlinux OS.

Java Solutions


Solution 1 - Java

As indicated here, JavaFX is no longer included in openjdk.

So check, if you have <Java SDK root>/jre/lib/ext/jfxrt.jar on your classpath under Project Structure -> SDKs -> 1.x -> Classpath? If not, that could be why. Try adding it and see if that fixes your issue, e.g. on Ubuntu, install then openjfx package with sudo apt-get install openjfx.

Solution 2 - Java

This should be your perfect solution. Try and enjoy. If some command does not work properly that means if you get any error, try to solve it yourself. I have given you the main thing you need. If your application is in a different location, or your system architecture is different, solve it yourself. It's very easy to do it. Just follow my given solution.

Step 0:

sudo apt-get install openjdk-8-jre

Step: 1

sudo apt-get install openjfx

Step 2:

sudo cp /usr/share/java/openjfx/jre/lib/ext/* /usr/lib/jvm/java-1.8.0-openjdk-amd64/lib

Step 3:

sudo cp /usr/share/java/openjfx/lib/* /usr/lib/jvm/java-1.8.0-openjdk-amd64/lib

Step 4:

sudo chmod 777 -R /usr/lib/jvm/java-1.8.0-openjdk-amd64

now open a new project or rebuild your project. Good luck.

Solution 3 - Java

You can use the one that comes with IntelliJ: <intellij>/jre64/lib/ext/jfxrt.jar.

Solution 4 - Java

You need to download the java-openjfx package from the official Arch Linux repos. (Also, make sure you have the openjdk8-openjdk package). After doing that, open your project in Intellij and go to Project-Structure -> SDKs -> 1.8 -> Classpath and try removing the old JDK you had and clicking on the directory for the new JDK that will now contain jfxrt.jar.

Solution 5 - Java

Sample Java application:

I'm crossposting my answer from another question here since it is related and also seems to solve the problem in the question.

Here is my example project with OpenJDK 12, JavaFX 12 and Gradle 5.4

  • Opens a JavaFX window with the title "Hello World!"
  • Able to build a working runnable distribution zip file (Windows to be tested)
  • Able to open and run in IntelliJ without additional configuration
  • Able to run from the command line

I hope somebody finds the Github project useful.

Instructions for the Scala case:

Additionally below are instructions that work with the Gradle Scala plugin, but don't seem work with Java. I'm leaving this here in case somebody else is also using Scala, Gradle and JavaFX.

  1. As mentioned in the question, the JavaFX Gradle plugin needs to be set up. Open JavaFX has detailed documentation on this

  2. Additionally you need the the JavaFX SDK for your platform unzipped somewhere. NOTE: Be sure to scroll down to Latest releases section where JavaFX 12 is (LTS 11 is first for some reason.)

  3. Then, in IntelliJ you go to the File -> Project Structure -> Libraries, hit the ➕-button and add the lib folder from the unzipped JavaFX SDK.

For longer instructions with screenshots, check out the excellent Open JavaFX docs for IntelliJ I can't get a deep link working, so select JavaFX and IntelliJ and then Modular from IDE from the docs nav. Then scroll down to step 3. Create a library. Consider checking the other steps too if you are having trouble.

It is difficult to say if this is exactly the same situation as in the original question, but it looked similar enough that I landed here, so I'm adding my experience here to help others.

Solution 6 - Java

You might have a lower project language level than your JDK.

Check if: "Projeckt structure/project/Project-> language level" is lower than your JDK. I had the same problem with JDK 9 and the language level was per default set to 6.

I set the Project Language Level to 9 and everything worked fine after that.

You might have the same issue.

Solution 7 - Java

Another way to resolve the problem : Click the left mouse's button on the project folder in the project structure at the left, and click on "open module settings" in the list of actions In the new windows, click on SDKs which is under the menu title "Platform settngs" Then check on the "Classpath" list if you can find the jfxrt plugin path, if not, click on the + symbol on the right and select the repertory of the jfxrt plugin (C:\Program Files\Java\jdk1.8.0\jre\lib\ext\jfxrt.jar on my desktop)

Solution 8 - Java

In IntelliJ Idea,

Check the following things are configured properly,

Step 1:

File -> Setting -> Plugins -> search javafx and make sure its enabled.

Step 2: Project Structure (Ctrl+Shift+Alt+s)

Platform Settings -> SDKs -> 1.8 -> Make sure Classpath should have "jre\lib\ext\jfxrt.jar"

Step 3:

Project Settings -> Project -> Project SDK - should be selected 1.8

Project Settings -> Project -> Project language level - configured as 8

Ubuntu: If not found jfxrt.jar in your SDKs then install sudo apt-get install openjfx

Solution 9 - Java

If you are working with IntelliJ and JDK 11

1. go to project structure ctrl + alt + shift + s.

2. add the mising javafx libraries in the Global Libraries section.

enter image description here

3. add a module-info.java file with the required dependencies to your module.

> module modulename { > requires javafx.fxml; > requires javafx.controls; > opens sample; > }

4. rebuild the project !

5. enjoy !

Solution 10 - Java

I had the same problem, in my case i resolved it by:

  1. going to File-->Project Structure---->Global libraries
  2. looking for jfxrt.jar included as default in the jdk1.8.0_241\lib (after installing it) 3)click on + on top left to add new global library and i specified the path of my jdk1.8.0_241 Ex :(C:\Program Files\Java\jdk1.8.0_241).

I hope this will help you

Solution 11 - Java

I am using apache maven with java 11 and I was able to remove all java fx problems by adding this dependency to my pom.xml file:

    <!-- JAVA FX -->
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>17.0.1</version>
    </dependency>

Solution 12 - Java

For me the simplest solution was to use Amazon Corretto, it is pretty much same as Oracle java.

Follow the steps:

  1. Go to Intellij, File -> Project Structure
  2. Go to SDK
  3. Download SDK
  4. From the dropdown, choose 1.8 as Java 1.8 version comes bundled with JavaFX library.

And you are good to go.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionrob111View Question on Stackoverflow
Solution 1 - JavaRyan JView Answer on Stackoverflow
Solution 2 - JavaHimel RanaView Answer on Stackoverflow
Solution 3 - JavaRok StrnišaView Answer on Stackoverflow
Solution 4 - JavapatterkyleView Answer on Stackoverflow
Solution 5 - JavaPeter LambergView Answer on Stackoverflow
Solution 6 - JavaRaphael SView Answer on Stackoverflow
Solution 7 - Javauser10899964View Answer on Stackoverflow
Solution 8 - JavaStoneView Answer on Stackoverflow
Solution 9 - JavaSaif FaidiView Answer on Stackoverflow
Solution 10 - JavaDjak aimView Answer on Stackoverflow
Solution 11 - JavaStimpson CatView Answer on Stackoverflow
Solution 12 - JavaAakash ParasharView Answer on Stackoverflow