Why can't IDEA find JavaFX package after upgrade JavaFX Project to JDK 17 using Azul Zulu Builds of OpenJDK with FX?
Asked Answered
S

1

6

I have a Java FX project and upgraded the project to JDK 17 using the following Azul Zulu Build of OpenJDK with JavaFX

https://www.azul.com/downloads/?os=windows&package=jdk-fx

Does anyone have a clue why Intellij can't find JavaFX package using JDK 17 from Azul Zulu Builds of OpenJDK with FX?

Suffering answered 19/10, 2021 at 15:0 Comment(0)
W
3

I provide two solutions:

  1. Using the Azul distribution which includes the JavaFX modules (which is what you asked for),

  2. Using the Azul distribution which does not include JavaFX, and use the JavaFX modules from Maven Central using a build tool.

I recommend solution 2 using a build tool. It is a little quicker to set up and a more portable, flexible and extensible approach for future development work.

Alternate JDKs

These instructions should also work perfectly fine for other JDK and JavaFX distributions, such as those packaged by Belsoft Liberica, Amazon Correto and Eclipse Temurin.

To use an alternate vendor for the JDK, choose to download the appropriate version from the selected vendor, either:

  1. Manually, using the Add JDK option as outlined below, OR
  2. Automatically, letting Idea perform the download from the vendor you select (using the Download JDK option as also outlined below).

Solution 1: Use Azul distribution with in-built JavaFX modules

Download Azul JDK:

  1. Go to the Azul download site, selecting the appropriate versions, platform, and package (use JDK FX as the package not JDK)
  1. Extract the downloaded package to a location on your machine.

Create a Java project (not a new JavaFX project):

  1. File | New Project... | Java

  2. Project SDK | Add JDK...

  3. Choose the location you have extracted your Azul JDK with JavaFX download.

  4. Leave default options, choose Next a few times.

  5. Name the project and select Finish.

Create a JavaFX HelloWorld.java class:

  1. Right-click on src, choose New | JavaFX Application.

  2. Name it HelloWorld.

  3. Edit the contents of the HelloWorld application to be:

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.stage.Stage;
    
    public class HelloWorld extends Application {
    
        public static void main(String[] args) {
            launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) {
            primaryStage.setScene(new Scene(new Button("hello, world")));
            primaryStage.show();
        }
    }
    

Run the new JavaFX application in the IDE using Azul JDK + JavaFX runtime:

  1. Open the HelloWorld.java class, click the Run application icon in the gutter, and select Run 'HelloWorld.main()'.

Troubleshooting

If you do the above and JavaFX classes cannot be found, you have probably not used a JDK which includes JavaFX.

In which case, unless you change JDK versions to one which does include JavaFX, you should download the JavaFX SDK from openjfx.io and follow the Idea project setup information provided there.


Solution 2: Use Azul, but source JavaFX modules from Maven Central

The solution below is to use Azul runtime with JavaFX modules sourced from the Maven Central Repository using Maven (or Gradle).

Create a JavaFX project:

  1. File | New | Project... | JavaFX
  2. Edit the project name to whatever you want.
  3. Leave default options, choose Next | Finish.

Download and use Azul JDK in your project

  1. File | Project Structure | Project SDK | Download JDK...
  2. Choose Vendor Azul Zulu Community.
  3. Download | OK

You only need to do the Azul download and add step if you want to use it instead of the default JDK used for new Java projects in your IDE setup.

Run the new JavaFX application in the IDE using Azul JDK runtime and maven JavaFX modules:

  1. Open the HelloApplication.java class, click the Run application icon in the gutter, and select Run 'HelloApplication.main()'.
Worthwhile answered 19/10, 2021 at 18:27 Comment(3)
The important thing in Solution 1 seems to be the step: Create a Java project (not a new JavaFX project). If you go the select the JavaFX project, it seems not able to find the JavaFX.Idonna
@AndrewS Good to hear that it was easy for you to get started with JavaFX development using Eclipse. This question was for Idea and using Zulu builds that include JavaFX in that environment, so the first solution was added to address that directly. Without those constraints, to get started with JavaFX development, just following the Idea new JavaFX project wizard, as mentioned in the second solution, is also quick and hassle-free IMO.Worthwhile
Actually scratch my last comment and and please take my humble apologies as your solution is good, very good in fact.Epoxy

© 2022 - 2024 — McMap. All rights reserved.