This question already has an answer here:
JavaFX applications built to target Java 8 - How to keep running with Java 11?
(1 answer)
Closed 4 years ago.
Many work environments continue to stay on JRE8 -- I'm a little confused on how to proceed with developing for the latest versions of Java. I compile JavaFX applications with Java SE 8 using NetBeans 9. Is there a way for me to start distributing via JDK 9, 10, and 11+ but still keep it compatible with all the JRE8 environments?
Or once I compile via JDK11, will it only be compatible when or if an environment upgrades their runtime? Or can I distribute a completely separate jar that runs without the need for a JRE and start today (even if they stay on JRE 8)?
There is a break between Java 8, and the modular Javas 9+. Though the module system has support for combined non-modular and modular code, JavaFX becomes OpenJFX, and I would not rely on there being one code base for long.
Also mind that modular means you can deliver your application with JRE parts as a small standalone executable.
So develop in Java 11+, possibly "convert" the sources to java 8 with a small tool written yourself. Restrict the usage of var and other short-cuts. (Maybe develop in java 8 and convert to Java 9+?).
Related
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.
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)
Setting the correct PATH for Eclipse
(7 answers)
Closed 2 years ago.
I have been having trouble with Java for my studies. I downloaded the latest version of the JDK, JDK 14. Now I tried to install Eclipse, it states that I do not have a JVM. So I am trying to download the JRE for it, but there is none. Can anyone recommend to me what I should do? Or do I need to uninstall the newest version and download a lower version?
No.
a JDK is a superset of a JRE; anything a JRE can do, a JDK can do. There is never any reason to install a JRE and there never has been*.
JREs are intended for 'end users' (non-coders who just want to run java apps, not write them or debug them). The model where you write an app and distribute some jars, and the user that receives your desktop java app is then responsible for having a java virtual machine on their machine (and they are responsible for keeping it up to date, secure, etc) – is dead. It died with JDK9. Officially. Replaced by jlink and such. That's why JDK9 has no JRE, nor do any versions after wards, and they never will again.
Because, starting with JDK9, you are responsible for that VM. You install it, you update it. jlink and co. help with this.
Eclipse, intellij, etc tend to still rely on you installing a JDK yourself; after all, you need one to develop java, so might as well use that. The point is, eclipse has run on JDKs since forever.
If the eclipse installer has issues finding your VM, that's possibly because JDK14 is brand new and whilst the latest version of eclipse does support it, maybe you have an older one. I suggest trying JDK11 (you really shouldn't run java apps on not-JDK11/JDK8; you'd want a long-term support version). Eclipse is perfectly fine running on JDK11, whilst you have a project that compiles against, and only runs on, JDK14. You can still run it, debug it, etc.
Does the Conscrypt library (https://github.com/google/conscrypt), work with Java 11? I know that it supports JDK 8 and 9, but has anyone tried it out with JDK 11? This is needed in a new project I am working on, using Java 11, in which I need to leverage Conscrypt's SSL / TLS features.
It seems this project isn't build on the JPMS.
What this means is, yes, it will work in a Java 11 environment, and it will be "transformed" to an automatic module.
The fact that you state it already works in a Java 9 context make it even more clear it will work in a Java 11 environment too.
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!
Can I use a jar, compiled in Java 7 as a dependency in a project that is compiled for compatibility with Java 6? I do not have the source code of the dependency. I have the compiled jar as a maven dependency.
Can I use a jar, compiled in Java 7 as a dependency in a project that is compiled for compatibility with Java 6?
Let's unpick this:
You have a project that is compiled so that will run on a Java 6 JRE. (Lets suppose that you only use Java 6 APIs in that project.) The .class files for this project must have a classfile format major version less or equal to 50 ... otherwise a Java 6 JRE won't be able to load them.
Then you have a dependency that is "compiled in Java 7". That could mean one of two things:
It could have been compiled using a Java 7 tool chain but with a target version of Java 6.
It could have been compiled using a Java 7 tool chain for Java 7.
In both subcases above above, you should be able to use the dependency in your Java 6 project if you run the project on a Java 7 JRE1. A Java 7 JRE can load and run classfiles compiled for Java 6. In one of the subcases, you will be loading classes with two (or more) class version numbers. But that is OK.
On the other hand, if you try to run the code on a Java 6 JRE, then:
Subcase 1 will work provided that the Java 7 dependency doesn't make use of any Java 7 (or later) APIs; i.e. it only uses Java standard classes, methods, etc that were present in Java 6 or earlier.
Subcase 2 will not work. The Java 6 JRE won't be able to load the dependency. Indeed, if the dependency is static (i.e. the project source code has compile time dependencies on the APIs of the dependent), then the project code won't build ... because the Java 6 compiler should refuse to read the dependency's newer version classfiles.
The most advisable approach is to migrate your project and your execution platform to Java 7. Or better still to Java 8 or Java 11, since Java 7 is EOL'd
If you can't do that, the next best thing would be to avoid using the Java 7 dependency ... until you can upgrade.
If you have customers who insist they you continue to support Java 6, then they are impeding your ability to progress your product line. They should be charged a premium for that.
If you have decided to avoid upgrading your Java platform for internal reasons, this decision is accumulating technical debt ... that your organization will need to "pay down" that debt in the long term.
1 - .... or JDK. A JDK is equivalent to a JRE for the purposes of running code.
In your case you actually ask if there is Forward Compatibility between Java 6 and Java 7. Generally speaking Java does not support Forward Compatibility as the 1.7 JVM cannot run code compiled with 1.6. This happens mainly because the version of 1.7 compiled Java bytecode is not known by the older version (1.6).