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.
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.
dist
folder: java --module-path /path/to/javafx-sdk-11/lib:../build/modules -m javafx11/javafx11.HelloFX
. –
Eject 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.
You say you are migrating to OpenJDK11/OpenJFX11 but why do you start this endeavour by building both the JDK and JFX yourself? It would be much easier to just download an EA build from here http://jdk.java.net/11/ and here http://jdk.java.net/openjfx/ Also, starting with JDK11 JavaFX is not part of the JDK anymore, so it can be built separately from the JDK. I am not sure your build instructions are up-to-date.
© 2022 - 2024 — McMap. All rights reserved.