JavaFX comes with JDK 8? - java

I have multiple questions regarding JavaFX.
Does JavaFX come with JDK 8? Does JavaFX also require its own runtime environment?
I looked in my computer (I have JDK and JRE installed) but could not find the JavaFX. Does this mean that JavaFX has its own seperate runtime environment and development kit? If so, where can I find the download links?
If somehow it is already downloaded on my computer, how does JavaFX work? Is it similar to Swing or completely different?
Edit Jan 2020 for those who stumble upon this question: With JDK 11, JavaFX is standalone; see jewelsea's answer below. Antonio Raposo's answer applies for JDK 8, but note that it is outdated.

JavaFX is bundled with JRE 8 and JDK 8. The JavaFX jar is jfxrt.jar and resides in the ext folder.
To deploy an application the only requisite is that the JRE 8 is properly installed.
There are similarities between JavaFX and Swing, but also differences. The best way to start is by reading the documentation available at the JDK site. Be careful to read JavaFX 8 pages and not JavaFX 2 pages as there are some differences and some old examples might not work.
You may also be interestes in one or other example I am posting in my blog A Cup of Java

Update Jan 2020
JDK 8 versions of JavaFX are now outdated.
Modern JavaFX versions (11+) are currently available from:
https://openjfx.io/ - documentation
https://gluonhq.com/products/javafx/ - hosted downloads
JavaFX libraries are usually not shipped standard with most OpenJDK or Oracle JDK versions. Instead JavaFX is available as a seperate set of libraries, modules and a SDK. Instructions on including JavaFX with your runtime distribution and developing with JavaFX are included at the openjfx.io link above.
Liberica JDK distributions by BellSoft currently ship with included JavaFX libraries and SDK tools. Or you can choose an OpenJDK version which does not include JavaFX from https://adoptopenjdk.net/ and add on a JavaFX distribution via following installation instructions at https://openjfx.io/ or as a maven or gradle dependency (also documented at the openjfx.io link).
JavaFX 8 tutorials hosted at Oracle are high quality and still relevant for use with later JavaFX versions.
Original Answer for JDK 8
JavaFX for Oracle Java 8 is not a separate installation. JavaFX is included in Oracle JDK 8 running on OS X, Linux x86 and Windows. The best place to learn more about this is the Oracle Client Technologies documentation for JavaFX.
Oracle used to distribute a binary version for Linux ARM as well, but I think that is only available by compiling the OpenJDK source now.
OpenJDK 8 binary installations, such as those which ship with Ubuntu, don't currently include JavaFX by default. For Ubuntu, it seems you can install a separate apt package for JavaFX. A user commented on another answer that the command for this is: sudo apt-get install openjfx (though I haven't an installation of Ubuntu to try it on). For more information on the relationship of OpenJDK and JavaFX, read: JavaFX and OpenJDK.
One thing that may be confusing you is that a very early version of JavaFX (1.x) was distributed as a separate download and development kit and implemented a new language called JavaFX Script which was different from Java. However, that early version of JavaFX is now no longer supported and should not be used. As of JavaFX (2.x) the JavaFX system was completely rewritten to provide a straight Java API and no longer use JavaFX Script. As of Java 8, JavaFX was completely integrated into Oracle JDK and no longer distributed as a separate download by Oracle. Being a Java API for Java GUIs that is part of the Oracle JDK, JavaFX is similar (in that way) to Swing; so the Oracle JDK provides alternate and distinct toolkits in the form of Swing and JavaFX.

Related

How to run java program using Oracle JDK 17, if Oracle JDK 17 does not come with JRE [duplicate]

This question already has answers here:
How can I get Java 11 run-time environment working since there is no more JRE 11 for download?
(4 answers)
Closed 3 years ago.
We are planning to migrate our Java 8 project to use Java 11. But I noticed that Java 11 doesn't have a JRE folder.
In Java 9 and Java 10, folder structures are changed i.e. java\jdk1.x or java\jre1.x, where x is Java 9 or 10.
But in Java 11, I am getting only one folder, i.e. java\jdk-11. How will my client use my application without jre?
What I understood is that Java 11 is enforcing to modularize our application, and using jlink is needed to create our own jre to run the application in client.
Is my understanding correct?
For 20 years, the JDK shipped with a JRE which was just a subset of its functionality installed in a different directory on your system.
In fact, it shipped with TWO identical JREs, one installed inside the JDK installation directory and one outside it.
This has always puzzled me as it's a complete waste of effort on the part of the maintainers to make this so, and a complete waste of disk space on the computer you install it on, as that JRE just duplicates some of the things the JDK can do already.
Finally, with Java 11, Oracle and the OpenJDK team decided to end this silliness and just distribute a single thing, the JDK.
This JDK when installed is actually smaller on your hard disk than the old JRE alone used to be, removing even the somewhat valid argument that you'd want a separate JRE for devices with limited disk space, an argument that never explained why 2 JREs would be installed with a single JDK in the first place but was made to justify the need for a JRE as a stripped down runtime environment for the JDK.
Ergo, there is no need for a separate JRE, and there hasn't been one for a long time, let alone for including and forcibly installing it as part of the JDK installation.
And no, you don't need to create your own JRE. Just install the OpenJDK on the client machines and make sure you add the $JAVA_HOME/bin to the system path, just as you had to do with old JREs.
And oh, strip the Windows directory tree of any java*.exe files which some versions of the old JRE installer were wont to place there, as well as the system path which also had some weird entries added by some JRE installers.
tl;dr
How will my client use my application without jre?
➥ Bundle a Java implementation within your Java-based app.
Learn about:
Java Platform Module System
jlink (JEP 282)
jpackage (JEP 343)
Details
What I understood is that Java 11 is enforcing to modularize our application
No, modularization is not required, strictly speaking. Most existing apps can run as-is in Java 11. You can continue to develop in Java 11 without modularizing your code. But in your case, for a GUI desktop or mobile app, then you need to package a JVM within your app. Modularizing and using jlink tooling is probably the best way to go about that. In contrast a server-side Servlet-based app or Microservices server need not yet modularize, though likely a good idea to do so eventually.
I noticed that Java 11 doesn't have a JRE folder.
Oracle no longer intends for end-users to be installing a JRE or a JDK. Java Applets in a browser and Java Web Start app delivery are both being phased out, leaving the end-user with no need for a JRE. Java-based apps are expected to bundle their own Java implementation. The only folks consciously installing a JDK will be developers & server-side sysadmins.
Some folks are disappointed to see the passing of the Java Everywhere dream. And they may be annoyed to have to make a build of their app for every host OS (macOS, Linux, Windows, etc.). On the other hand, some developers are happy to be bundling a Java implementation (now smaller than ever) with their app, as that eliminates the hassle for the end-user to download-install-update a system-wide Java implementation. Also eliminates wrestling with corporate IT departments to install Java on users’ PCs. And bundling Java with app simplifies testing and support, as you know and control exactly what version and distribution of Java is involved. By the way, this bundling-Java-with-app is not exactly new: It has been supported by Apple for many years in the macOS & iOS app stores.
Important:
Understand clearly the nature of the OpenJDK project, as explained in Wikipedia
Read this white paper by Oracle of 2018-03, Java Client Roadmap Update
Read the white paper Java Is Still Free, authored by key members of the Java community.
Here is a flowchart diagram that may help you finding and deciding amongst the various vendors providing a Java 11 implementation.
Look at the AdoptOpenJDK project website to download the latest JRE and JDK.
I have used their nightly builds to work around the problem of missing JRE in JDK package. Just unpack JRE into JDK folder and this is going to be it.

How do I find the most recent version of JavaFX to implement in my build.gradle file?

What I believe is the official website, openjfx.io, tells me to use version 0.0.10 in gradle. However, It's incompatible with JDK 8 and 17, spitting out java.lang.UnsupportedClassVersionError: org/openjfx/gradle/JavaFXPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I looked through the JavaFX repo, but couldnt find a good version number to replace 0.0.10 with, but I don't think 0.0.10 is really the most recent one. Where can I find the most recent build number?
tl;dr
Currently the latest versions for JavaFX development would be:
JavaFX Gradle Plugin 0.0.10 (simplifies working with JavaFX 11+ in Gradle projects)
OpenJFX 17.0.1 (libraries that implement JavaFX, require Java 11 or later)
Java 17.0.1 (an LTS version)
JavaFX Gradle Plugin
Comments by Slaw point out that you seem to be confusing the Gradle plug-in for JavaFX with the OpenJFX libraries needed to run a JavaFX app.
The plug-in simplifies working with JavaFX 11+ for Gradle projects.
Currently, that plugin’s latest version is 0.0.10. See also the GitHub product page.
OpenJFX libraries
As for the OpenJFX libraries, see the Products Roadmap at GluonHQ.com. You will find 17.0.1 is the latest, with 18 in early-access.
The JavaFX (OpenJFX) releases have been synced to arrive at about the same time as the Java releases, and use the same major version number. A convenient approach.
But OpenJFX releases do not require the latest Java. The Release Notes for 17 says it requires Java 11 or later. Note that both Java 11 and 17 are Long-Term Support (LTS) versions.
I suggest you generally do your development work with the latest Java and the latest JavaFX while aiming your deployments at the latest LTS version of both. Note that Oracle recently announced a change in the LTS cadence from every three years to every two years. Presumably JavaFX will follow that as well.
See also the related Question, Which version of OpenJFX (JavaFX) and Scene Builder should I use with Amazon Corretto 11 (OpenJDK)?.

NetBeans: "Failed to automatically set-up JavaFX Platform"

I have been troubleshooting this error for the past few days - and have hit a brick wall. I am running NetBeans v11.3, and Ubuntu Bionic (v18.04.4).
I have installed Java versions 8 and 11 (openjdk) along with source code.
I have also installed javaFx versions 8 and 11 with source code.
I have even gone to "Tools -> Java Platform Manager" and ensured that v8 and v11 of Java are properly installed along with the appropriate "Platform Sources".
But I still get the error mentioned when I try to create a new JavaFX project.
Any help would be very much appreciated.NetBeans JavaFX project create error
I have never tried to use JavaFX on openJDK, try out with Oracle JDK, as far as I know this is the best choice for using JavaFX, also try to edit the default platforms to match the appropiate system paths

How to use JavaFX in jdk11?

I am a beginner programmer and now I want to start GUI applications in java.(as I previously worked on java too). I started reading some books on FX but its not compiling on JDK11 .. Do I need to use jdk8 or is there any way i can do it on jdk11 too?
JavaFX has become unbundled from JDK11 (both Oracle's official JDK and OpenJDK). In order to use JavaFX with JDK11, you'll have to download the standalone JavaFX11 runtime.

How do I use JavaFX 11 in Eclipse?

I have some trouble with JavaFX. I wanted to start creating apps, desktop or mobile, at least something. So I found out I could use the JavaFX library for it. But as far as I understood, it was excluded from JDK 9. I'm actually using OpenJDK 11 on Ubuntu 18 (though Eclipse writes I have the JavaSE 10 environment, that is where I'm also a bit confused) and I installed OpenJFX using sudo apt install openjfx and I can't make Eclipse work with JavaFX.
I'm not sure if there's any sense not to use JDK 8 with the included JavaFX, but anyway, how can I use JavaFX in such conditions in Eclipse?
There are multiple points in your post which needs clarification. I will try to answer them in different bullet points:
But as far as I understood, it(JavaFX) was excluded from JDK 9.
JavaFX will be decoupled from Oracle JDK starting JDK 11. I stress on Oracle JDK because JavaFX was never a part of OpenJDK. Not even in OpenJDK 8.
I'm actually using OpenJDK 11 on Ubuntu 18 (Though eclipse writes I have JavaSE 10 environment, that is where I'm also a bit confused)
For Java 11 support in Eclipse, you need to install
Java 11 Support for Eclipse Photon plugin.
Here are a few Examples on how to run Java 11 applications in Eclipse
I installed openjfx using sudo apt install openjfx and I can't make eclipse work with JavaFX.
I'm not sure if there's any sense not to use JDK 8 with included JavaFX, but anyway, how can I use JavaFX in such conditions in eclipse?
Since OpenJDK 11 or Oracle JDK 11 will not come bundled with JavaFX, your best bet is to either download the JavaFX SDK from here or here and load them in your IDE.
If you are used to build tools, you can directly use the JavaFX runtime jars which are available in Maven Central.
For a tutorial on how to run JavaFX 11 on OpenJDK 11, you can follow:
Getting Started with JavaFX 11
JavaFX on JDK 11
JavaFX 11 and Eclipse
At the time of writing this post, you need Eclipse 4.9M3 to work with JavaFX 11.
Once you have eclipse, JDK 11 and JavaFX 11 SDK, you can either opt to create:
Module based project
Non-module based project (No module-info.java required)
Module based Project
Create a Java project and add JavaFX jars from the Java FX 11 SDK to the module path of the project.
Create a module.info and declare its dependency of javafx.controls module. javafx11 is the name of the package which contains your Java file.
module javafx11 {
requires javafx.controls;
exports javafx11;
}
Run the program \o/
Non-module based Project
Create a Java project and add JavaFX jars from the Java FX 11 SDK to either the module-path or classpath of the project.
Add the following JVM args to the run configuration of the project:
--module-path=path-to-javafx-skd/lib --add-modules=javafx.controls
Run the program \o/
tl;dr
To most easily get started with JavaFX, use the Oracle-branded release of Java 8 where JavaFX 8 is bundled and easily available.
For technical details, see Using JavaFX in JRE 8. Look to the Linked and Related sections of the web page for many related postings.
Java Modularization
The Java platform is in the process of a sweeping reformulation, known as modularization.
Previously, Java SE (standard edition) was one big monolith of software, ever-growing with more and more being added. No single app ever uses all of it.
A decision was taken to break Java SE into many separate chunks to be defined formally as “modules”. One major benefit is that an app may be bundled with a Java SE runtime composed of only the modules actually needed, with unused modules omitted. See the jlink tool.
As a byproduct of this modularization, some older and less-popular parts such as CORBA are being dropped, to no longer be carried as a standard part of Java (though offered for other parties to pick up if they so decide). Similarly, some Java EE related modules will be removed from Java SE and turned over to the Jakarta EE project, logically a more appropriate home. See JEP 320: Remove the Java EE and CORBA Modules.
The process of modularization and reorganization is a years-long ongoing effort. Much was done in Java 9 and Java 10. Some of the final steps are being done in Java 11.
One of these steps being taken in Java 11 is to cease bundling JavaFX with Java SE. See:
The Future work section of the JavaFX Wikipedia page
The 2018-03 Oracle blog post, The Future of JavaFX and Other Java Client Roadmap Updates
The 2018-03 Oracle white paper, Java Client Roadmap Update
The curse, May you live in interesting times
So getting started with JavaFX development right now will be easiest if done with Java 8. The JavaFX libraries are bundled in with Java 8. And you need not learn about modularization, nor need to wrestle your IDE (such as Eclipse) and project settings to recognize modules. If you do not have a pressing need to use the very last versions of Java or JavaFX, stick with 8 until the modularization process and tools gets smoothed out, likely next year 2019.
If you insist on using Java 11, you need to learn about:
Java modularization in general, including the module-info.java file.
Updating your IDE (Eclipse, etc.) and other tools to later versions supporting both modularization and Java 11.
Configuring modules in your build tools, such as Maven or Gradle
Configuring modules in your IDE, such as Eclipse
Downloading JavaFX modules, or using a dependency manager such as Maven to do so
Those points are too much to cover here, and have been covered in many other Questions on Stack Overflow. Besides, Java 11 has not yet been formally released.
Perhaps this article will help, How to Create a Project With JavaFX on JDK 11.
To learn much more about Java modularization, read the blog and the book, The Java Module System, by Nicolai Parlog.
I've had to struggle through this on about 20 computers now, so I made the following checklist:
[ ] download javafx11 from javafx11's website, put on desktop
[ ] create a MODULE based project
[ ] right click project, go to BUILD PATH
[ ] add the downloaded javafx.base/control/graphics as external jar files
[ ] put the files in a package (eg: my_big_package)
[ ] put the following in the module.java file:
module javafx11 {
requires javafx.controls;
exports my_big_package;
}
[ ] eat a donut from the break room
If you're not married to Eclipse and/or just trying to learn (or are a student with an unhelpful professor/TAs), BlueJ currently has JavaFX already built into it and ready to go, so no extra setup or download is necessary. Neat!

Categories

Resources