JavaFX deployment library not found in active JDK
Solution 1
As @mipa points out, you don't need to build neither Java 11 nor JavaFX 11 in order to migrate your existing projects.
As for Apache NetBeans 9.0, the current ant build files for JavaFX project don't support JavaFX 11 yet. It is always looking for the JavaFX jar, and it will stop when it is not found. This is somehow legacy from the old days (before Java 8), when JavaFX was not part of the JDK and you had to add the jar manually.
For instance, when you try to create a new JavaFX project, you will get this error:
But this doesn't mean that you can't run JavaFX 11, with or without NetBeans 9.0.
Running on terminal
You can run your Java/JavaFX 11 project from a terminal. You can follow this getting started guide for a detailed step by step.
In a nutshell, all you need is:
export PATH_TO_FX=/path/to/javafx-sdk-11/lib
javac --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX.java
java --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX
where HelloFX.java
is:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloFX extends Application {
@Override
public void start(Stage stage) {
String version = System.getProperty("java.version");
Label l = new Label ("Hello, JavaFX 11, running on " + version);
Scene scene = new Scene(new StackPane(l), 300, 200);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Modular Project
Create a modular project on NetBeans 9.0, and add a module (for the sake of simplicity I named it javafx11
, which is not a recommended name).
Before adding the code, let's add the JavaFX library to the module-path.
This library is just the folder under my local download of JavaFX: /Users/<user>/Downloads/javafx-sdk-11/lib/
. Of course, if you have built it yourself, you can point to that location instead.
Now I can define the module:
module javafx11 {
requires javafx.controls;
exports javafx11;
}
and add the above HelloFX
class to the javafx11
package.
Now the project will run perfectly fine.
Even if you are still using ant
, in this case, the build files are updated to the module-path changes, and there is nothing JavaFX specific, so the project runs without any issue.
Java project
If the modular project works, then a regular Java project will work as well on NetBeans 9.0.
Create a Java project (again, not a JavaFX project), add the JavaFX library to the module-path as above, and now you will need to add these VM options both for compiling and running:
--module-path=/path/to/javafx-sdk-11/lib --add-modules=javafx.controls
The project should run fine.
Maven
Another approach is using Maven or Gradle instead of ant.
Just create a Maven -> JavaFX project, modify the pom.xml file and add the JavaFX dependencies:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11-ea+23</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11-ea+23</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>11</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1.1</version>
<!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>javafx11.HelloFX</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Clean, build and run from NetBeans, it should work just fine.
For Gradle, the same can be done, if you include the Gradle plugin for NetBeans.
Solution 2
It's a problem with Netbeans 9. I had used the Sun JDK, now Oracle JDK for many years with netbeans. In Netbeans 7.2 there was an option to manually add JFX jar files. Then, JFX was embedded into Oracle JDK8, and that option isn't available now. Some weeks ago I was informed that Oracle JDK won't be free anymore on next year, so I started to migrate to Open JDK10 and I'm having the same issue that you. That's because Open JFX is not embedded into Open JDK. If you try with Oracle JDK11 which already is GA, you won't have any issue building JFX apps. The issue is when you set in NetBeans as Java Platform an Open JDK, it expects to JFX to be inside the JDK itself, but Netbeans won't ask you for a JFX folder or something like it did in earlier versions.
Admin
Updated on November 26, 2021Comments
-
Admin over 2 years
I am migrating to OpenJDK 11 and OpenJFX 11. I have successfully built both from the source, and as per the OpenJFX wiki used the --with-import-modules=[path_to_modular_sdk] arg to build the JDK. everything goes well until I try to build a simple "Hello World" test project in Apache Netbeans 9; at this point I get the following error: "JavaFX deployment library not found in active JDK". Tried searching for info on this but could not find anything relevant. If anyone could shed light on what is causing this I would much appreciate it. Thanks for any help. Patrick.
-
Admin over 5 yearsActually I did both. However it is necessary to build the JDK with the import options to include the JFX as it is no longer possible to just overlay the JFX build over the JDK build. I still had the same problem regardless of whether I used my builds or EA builds. I am beginning to think this may be a build script problem in Netbeans 9, rather than a JDK/JFX problem.
-
mipa over 5 yearsThis is not true anymore with JDK 11. See description below by José.
-
Admin over 5 yearsHi Jose. Thanks for your explicitly detailed solution; worked great and now I can build correctly. I do have a question resulting from the Modular Project build though: the Main-Class is not being placed into the MANIFEST.MF file by Netbeans. I have tried setting the main class in the properties->run option but it still does not populate the MF file ... hence the program will not run. Did you come across this when you executed the example you gave? Thanks.
-
José Pereda over 5 yearsBy default if you run from NetBeans, the jar doesn't include the mainClass, and as you say, it doesn't run outside NetBeans, because of this missing attribute. You can run it from a terminal, as a module though, from the
dist
folder:java --module-path /path/to/javafx-sdk-11/lib:../build/modules -m javafx11/javafx11.HelloFX
. -
Admin over 5 yearsJose, I know this is a bit off-topic but you seem well versed in the Netbeans 9 capabilities: I know Apache's adoption of Netbeans is still a WIP but it seems to me to be a fundamental requirement that an IDE should be able to execute and debug a program from it's main UI. I don't understand why they have made it possible to run a normal Java project but not a modular one from the IDE GUI?
-
Naman over 5 yearsOn a side note, the maven-compiler-plugin can be updated and simplified.
-
Manius over 5 yearsThe Gradle plugin alternative won't install, at least from the Plugins dialog, because apparently the Groovy plugin dependency isn't in place yet. I don't care for using Maven, so I guess I'm forced to look at IntelliJ. At the risk of getting a "you're free to submit a PR yourself", I hope someone is going to be fixing these issues soon. Will try a manual install of the outdated Groovy plugin to see if that resolves it first. I guess the easy days of going through the NB project properties dialog to configure builtin Ant scripts are ending.
-
José Pereda over 5 years@Manius You can use the Gradle plugin on NetBeans 9/10. See openjfx.io/openjfx-docs/#IDE-NetBeans. Make sure you use the latest release 2.0.1
-
Manius over 5 yearsThat's what I tried with NB 9.0, and it said 2.0.1 in the description before this dialog: imgur.com/a/ajemUGe Complains about Groovy support, can't click Next.
-
José Pereda over 5 years