Adding JFXApp to existing non-JFX project

Answered

If you create a new JavaFX project, Intellij can compile the project just perfectly.

 

However, if you create a regular Java project, then add a JavaFX application to it, IntelliJ can no longer compile the app, as it complains it can't find the JavaFX packages.

 

This is on the same machine with only one SDK installed that has JavaFX support (Java 9).

 

How can I add a JavaFX app to a project that wasn't originally created as a JavaFX app and have IntelliJ compile it?  Please help.

6 comments
Comment actions Permalink

I've created a new Java Hello World project and a new Java FX project. Then I've copied the files from the src directory of the Java FX project to the Java Hello World project and everything works just fine.

0
Comment actions Permalink

Hi Serge,

 Thank you for looking into this.  This is happening to me on two different computers now.  Check out this screenshot.

 

You can see IntelliJ doesn't indicate in the source file that javafx can't be found, but in the build output JavaFX  classes can't be found.  

0
Comment actions Permalink

Try to remove the JDK configuration and add it again, you should have the following in the JDK classpath:

If the issue persists, please upload the project that doesn't work here: https://intellij-support.jetbrains.com/hc/articles/206869619.

0
Comment actions Permalink

Hello. This worked for me:

1. Right-click on the project name > open module settings Global Libraries > right click on JavaFx and click Add to Modules.

2. Right click the src folder > new > module-info.java > inside the curly braces write :

requires javafx.fxml;
requires javafx.controls;

opens sample;

1
Comment actions Permalink

Any updates here?

0
Comment actions Permalink

Maxhager28

Please clarify the problem. What exactly is not working for you? Share your project at https://uploads.jetbrains.com.

0

Please sign in to leave a comment.