Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JDK without JRE in Java 11 [duplicate]

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?

like image 211
Maha Lak Avatar asked Oct 01 '18 05:10

Maha Lak


People also ask

Do I need JRE if I have JDK 11?

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.

Do I need Java JRE if I have JDK?

The JDK includes the JRE, so you do not have to download both separately. To understand the version-string scheme that is used to distinguish various JDK and JRE releases, see Version-String Format.

Can I use JRE 8 and JDK 11?

Yes. The number of the kit to produce apps on the Java platform, the JDK, is numbered to match the version of Java platform. 8 for 8, 11 for 11, and so on. You can use JDK 11 during development for earlier Java if your project is explicitly configured to be compiled and built for the earlier Java only.


2 Answers

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.

like image 122
jwenting Avatar answered Sep 21 '22 15:09

jwenting


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.

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


Motivations in choosing a vendor for Java

like image 32
Basil Bourque Avatar answered Sep 20 '22 15:09

Basil Bourque