2

I am currently trying to learn javafx but I'm having the problem of my laptop not having javafx install. I am using a windows 10 machine, I currently have jdk14 installed which is working fine as I've been recently running and compiling java code. I've looked all over the internet and cannot find any links that instruct me on how to install javafx, all the links I've found have been installing it and running it with an IDE like eclipse, netbeans and intellij but I am using atom to do my coding.

I have downloaded the latest version of javafx 14 from here and I assume that I will have to add the path variable to the environment variables in windows but I am not sure if doing so will get things to work so I'd thought I'd post here just to get so more knowledgeable help.

I know jdk 7 or jdk 8 has javafx built in but I would like to keep jkd 14 as I have programs already written using jdk 14.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
user2152012
  • 161
  • 1
  • 4
  • 17
  • 1
    Does Atom support Maven? I would strongly recommend managing JavaFX in versions >= 11 with a dependency management tool such as Maven. If so, you should be able to modify the instructions for other IDEs at https://openjfx.io/openjfx-docs/ – James_D May 22 '20 at 15:27
  • 1
    Just use the [Liberica](https://bell-sw.com/) OpenJDK release. They still distribute their runtime (>= 11) with matching compiled releases of JavaFX (renamed to LibericaFX for trademark reasons, but it's all there). – Elliott Frisch May 22 '20 at 15:34

2 Answers2

4

OpenJFX

First, know that Oracle has open-sourced an implementation of JavaFX as the OpenJFX project, a sub-project on the OpenJDK project.

Further development of JavaFX/OpenJFX is now led by the company Gluon. That development of OpenJFX is vigorous, with versions 11, 12, 13, 14, and now pre-release 15 arriving almost lock-step with releases of Java 11, 12, 13, 14, and 15.

Rather than manually downloading JavaFX, I recommend either of these approaches:

  • Obtain a JDK with OpenJFX bundled
  • Use a dependency manager to auto-download OpenJFX into your app

JavaFX bundled with JDK

Replace your Java implementation with one that bundles the open-source implementation of JavaFX known as OpenJFX.

You can find at least two such bundled JDKs:

  • LibericaFX from BellSoft is one such implementation of Java, based on the OpenJDK project.
  • ZuluFX from Azul Systems, announced here. Tip: On their download page, use the Java Package pop-up menu to choose either JDK FX or JRE FX. As of 2020-05, they have not yet released version 14 of their JavaFX bundle, but they have versions 8, 11, and 13 of their ZuluFX. I suggest checking back later for 14, or contact the company. ZuluFX is free-of-cost, with an invitation to talk if you are interested in buying support for JavaFX.

Here is a flowchart I made to help folks in selecting a vendor of a Java implementation. Notice the “OpenJFX bundled?” branch near the bottom.

Flowchart guiding you in choosing a vendor for a Java 11 implementation

Motivations in choosing a vendor for Java

OpenJFX as a dependency

I do not know if Atom can work with a dependency manager, but for your information…

Configure your build tool such as Maven or Gradle to automatically download and bundle OpenJFX as a dependency.

For Maven, here is the current POM configuration for javafx-controls, for version 14 of both Java and OpenJFX. And you will likely want JavaFX Maven Plugin Maven Mojo (javafx-maven-plugin) as well.

Below is an example POM based on a real POM in a current JavaFX app of mine.

<project xmlns = "http://maven.apache.org/POM/4.0.0"
         xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>work.basil.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>14</maven.compiler.source>
        <maven.compiler.target>14</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>14.0.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>14</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>work.basil.jartran.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

You can create your Maven-based project by using a Maven archetype provided by the OpenJFX project. The POM seen above will be automatically created for you. You may need to update the version numbers.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
1

JavaFX is fairly easy to setup to use with JDK14. I took the v14 "JavaFX Windows x64 SDK" version from the site you mentioned. It is a ZIP so just extract it to a local directory. I my case I used: C:\java\javafx-sdk-14

Then you can add any JavaFX jar you need to use with JDK14 by adding them referenced from:

C:\java\javafx-sdk-14\lib\javafx.BLAH.jar

When you RUN the application you need to add the JavaFX modules into the command you use for Java.exe - in my case I only use the dependencies of javafx.controls (=>javafx.graphics/javafx.base) so I added this to the command to launch my app:

--module-path="C:\java\javafx-sdk-14\lib" --add-modules=javafx.controls

Once you know what JavaFX modules you need you can also package a new JRE including JavaFX using jlink command and the "JavaFX Windows x64 jmods" release - this avoids needing "--module-path / --add-modules" to every launcher. Example I saved the jmods release to C:\java\javafx-jmods-14 and this generates a standalone JRE including JavaFX:

jlink --module-path "C:\java\javafx-jmods-14;mods" --add-modules javafx.controls --output C:\jre.and.javafx

Then at runtime all commands I launch are simply variants of:

C:\jre.and.javafx\bin\java.exe --class-path ..\jars\BLAH.jar package.ClassName 
DuncG
  • 12,137
  • 2
  • 21
  • 33