skip to Main Content

So, I’ve coded a Java Swing application in my Debian PC, and compiled it with IntelliJ into a JAR file. However, while it runs normally on the system it was coded on, it causes a Java Exception when running on other Windows machines. When I run it on the command line to show more details about the exception, this is the output:

-jar out.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

Bare in mind that this happened even with a completely updated JRE.

Obviously, after encountering this issue, i did some research about it, and it came to me that i had to download the most recent JDK into my Windows system, as apparently Oracle stopped distributing JREs, so programs compiled in more recent versions of the JDK don’t run in computers that don’t have a JDK installed.
And this seemed to work – after installing said JDK, the program ran normally.

However, this still is an issue; not for me directly, but for those that may eventually use my software.

Let’s suppose, for example, that I make a program to help a friend of mine with something in his PC, written in Java. As he is not a developer, he doesn’t have any JDK installed on his PC, only a JRE that he may have previously installed. So, in order to make it so that he can run my program, i would have to make him install the most recent JDK into his computer, as everyone that would someday use a program that I made would have to install it as well, which doesn’t seem very practical for me.

So, in conclusion, this entire situation just made me very confused, especially as I can’t find anything in the internet that actually clearly explains what happened with the JRE – and that’s what im trying to understand better – What actually happend to the JRE? If it actually got discontinued, does that mean that everyone that wants to use a recently programmed java program have to install the JDK? Or is it just something that I am missing? Perhaps compiling in Linux instead of windows has something to do with it?

Also, I found some people saying that a fix to this issue would be to just downgrade my JDK to a version that the "most recent" JRE actually supports, but I just feel like that doesn’t quite make sense, as I would be missing on a lot of new Java features, kind of defeating the purpose of keeping the Java language updated.

So, can someone clarify all of this for me? Thanks in advance!

2

Answers


  1. tl;dr

    • Oracle is but one vendor of implementations of the Java specs.
    • Some JDK vendors do offer a JRE edition.

    Details

    Oracle is the owner of the Java™ brand, the publisher of the Java specifications, and leader of the Java community.

    So required reading is this Oracle white paper, Java Client Roadmap Update of 2020-05, and related blog post. This marks Oracle’s dramatic shift from their Java Everywhere strategy. Oracle no longer pursues the bundling of a JRE with every major operating system as had been done in the past.

    Instead, Oracle expects desktop apps to be shipped with a JVM contained internally. To this end they created the Java Platform Module System (JPMS), and produced the jlink and jpackage tools. If your app is modularized, you can bundle a JVM slimmed down to include only the parts your particular app actually uses.

    So you can see from this point of view, the need for a JRE evaporates. A JRE is just a JDK without build/compilation-related tools. If apps include a JVM, and users are no longer expected to be installing Java onto their desktop machines, then a JRE is unnecessary.

    As I recall, you are correct: Oracle no longer distributes JRE products, at least not to the public. But you should check with their sales force to be certain. But Oracle is not your only source for an implementation of the Java specs.

    You should read Java Is Still Free 3.0.0 (Oct 2021), by pillars of the Java community.

    Oracle is only one of several vendors providing JDK products. These vendors include Azul Systems, Adoptium by Eclipse Foundation, IBM, Red Hat, BellSoft, Oracle, Amazon, Microsoft, SAP, and more. All of their products are throughly tested. Most are based largely, if not entirely, on the OpenJDK codebase implementation of the Java specs.

    Some of these vendors choose to provide a JRE edition of their products. Such products may be useful in controlled environments such as the enterprise and education where an IT admin department may want to deploy and maintain a JRE across their users’ machines.

    If you decide you really want a JRE, examine the offerings of all the JDK vendors. Pay attention to the terms of their license.

    Tip: For JavaFX apps, you may be interested in a JDK/JRE that bundles the OpenJFX implementation libraries. At least two vendors offer such editions of their JDK/JRE products: Azul Systems and BellSoft.

    Login or Signup to reply.
  2. There is no real (i.e. unresolvable) issue here:

    • instruct the user to install a Java 17 JDK, OR
    • instruct the user to install a 3rd-party Java 17 JRE, OR
    • build your application to target Java 8 (which is the last version where Oracle JREs are available), OR
    • use jlink and jpackager to build a custom JRE and an installer so that the user doesn’t have to worry about finding and installing a JRE or JDK.

    The last means that you will be "on the hook" for dealing with any security issues1 in the embedded JRE that you are distributing in your app’s installer.


    What actually happened to the JRE?

    Oracle decided to discontinue distributing JREs starting with Java 9. This is old news. And Oracle gave their reasons for the business decision.

    See Basil’s answer for a longer exposition on how we got here. Be sure to read the documents his answer links to!

    If it actually got discontinued, does that mean that everyone that wants to use a recently programmed java program have to install the JDK?

    No. See above. There are other ways to handle this.

    Or is it just something that I am missing?

    Yes. See above.

    Perhaps compiling in Linux instead of windows has something to do with it?

    No. That has nothing to do with it. Though if you go the jlink + jpackager approach you will need to create separate distributables for each platform you want to support.


    1 – AFAIK that is main thing that Oracle was trying to achieve by withdrawing their JRE distros.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search