Getting this error when trying to run gradle build.
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
Now there's tonnes of similiar questions on StackOverFlow about this, but every suggestion doesn't work that I've found:
My Project/Module language level are the same (11)
The bytecode version of the project is also 11
There is only OpenJDK11 installation I'm using.
Path and JAVA_HOME variables point to the above installation.
There are no other lingering java/oracle enviromental variables.
Running java -version results in:
I don't understand what's happening. I can't see how it's using JRE 8 when I only have JDK 11. I'm at a total loss here.
It may be that the Gradle JVM is still set incorrectly. If you are using IntelliJ, you can change this by going to File > Settings > Build, Execution, Deployment > Build Tools > Gradle and change Gradle JVM to 11 (or to the Project JDK).
Related
I have a project with 3 modules. I am running them with Intellij. Everything worked fine until project was upgraded to java 17, I ran following commands in terminal:
sdk install java 17.0.3-tem
sdk use java 17.0.3-tem
In Intellij preferences Compiler -> Java Compiler -> Project bytcode version is set to 17 as well as all per module bytecode target versions.
I have tried to use both javac and eclipse compiler, also I have set the Gradle Jvm to temurin-17 in Intellij Build Tools -> Gradle, but I still get an error:
Error: LinkageError occurred while loading main class glow.MainKt
java.lang.UnsupportedClassVersionError: myproject/MainKt 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 58.0
What else do I need to do in order to get rid of this error?
I start up the NetBeans IDE 12.0 with a system environment JAVA_HOME (1.8) lower than what the IDE uses (14). The IDE output window of Maven execution seems to show that the project is run with JAVA_HOME for JDK 14, running project files this way.
But the exec-maven-plugin fails with java.lang.UnsupportedClassVersionError: com/mycompany/Start 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
This seems to indicate that Maven runs under 1.8 in the IDE, ignoring the IDE's own override setting of JAVA_HOME of 14. It uses the JDK as set in JAVA_HOME, because if I set JAVA_HOME to 14.0 before IDE startup then it works.
I am looking for the correct way, the right places, to set the JDK for any project specifically, regardless of the JAVA_HOME setting that is active when the IDE starts.
My case can be reproduced by running the IDE 12.0 with JDK 14.0 installed, but with JAVA_HOME set to 1.8. before IDE startup. I use the Maven project generated from the command at https://wicket.apache.org/start/quickstart.html - all set to defaults. The file to run is Start.java.
This is important to me because I must open many different projects with different JDKs so it is not practical to re-start the IDE with different JAVA_HOME settings each time. As it is, it appears that my setting is poorly defined - I must be missing something.
I should add that in the project properties, I have set the Build|Compile|Java Platform to JDK 14 (Default) as expected.
I have filed a NetBeans Issue
For maven, if you want the byte code of your project to be 1.8, try just setting variables used by the compiler plugin even if you're using a newer JDK.
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
If you want a different java install completely, then you might want to look into the toolchains. But I'd only go this route if the above doesn't meet your needs.
https://maven.apache.org/guides/mini/guide-using-toolchains.html
I am not familiar with NetBeans but hopefully it will read the compiler level for maven.
I'm learning how to use Gradle to build projects in IntelliJ. I want to build a project involving OpenJFX. However, I encounter this error.
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
> 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
From what I can figure out, Gradle is using Java 8 to run a Java 11 plugin. However, I put this in gradle.properties:
org.gradle.java.home=/C:/Users/<my user>/.jdks/openjdk-14.0.1
The reason it's in .jdks is because IntelliJ downloaded it earlier. The thing is, I told Gradle to use Java 14, yet it gives me an error as if it's being run by Java 8. What's wrong here?
According to the docs org.gradle.java.home property…
…specifies the Java home for the Gradle build process. The value can be set to either a jdk or jre location, however, depending on what your build does, using a JDK is safer. A reasonable default is derived from your environment (JAVA_HOME or the path to java) if the setting is unspecified. This does not affect the version of Java used to launch the Gradle client VM
So, this value is only used for build process (like compiling or running app or tests). Gradle spins up a child process for that, so the VM that performs tasks and the VM that runs the build script may not be the same.
It looks like you're using a Gradle plugin compiled with Java 11 (55.0), but your Gradle VM is Java 8 (52.0), so it cannot load and use plugin's class. You must use Java 11+ for Gradle VM itself.
Try running you build like JAVA_HOME=C:/Users/<my user>/.jdks/openjdk-14.0.1 gradlew.bat clean run.
I found out how to change Gradle's JVM. In IntelliJ, go to Preferences (Ctrl-Alt-S); then Build, Execution, Deployment; then Build Tools > Gradle. There's a little menu that lets you choose between the JVMs it recognizes.
Build Failure on Maven:
package javafx.application does not exist
I'm using JDK 8 because JDK 11 doesn't have JavaFX included by default.
I have openjfx listed in my pom file as a dependency.
I have JAVA_HOME set to:
$JAVA_HOME
bash: /usr/lib/jvm/java-8-openjdk-amd64: Is a directory
Is there an environment variable that needs to be set in order for Maven to find the JavaFX jars?
here is the terminal output and pom file
You are trying to use files compiled for version 54 (which is Java 10 according to https://en.wikipedia.org/wiki/Java_class_file#General_layout) and the Java 8 you are using does not understand any higher versions than 52.
You cannot use this javafx-base artifact with Java 8. Either revise your code or upgrade to at least Java 10.
Your Maven still use JDK 11.
Try Oracle JDK 8 for Linux https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html or you can install from software repos in Linux.
Try to remove, uninstall all things of JDK 11 (then check environment variables carefully, checking by command java -version and javac -version to be sure you are using JDK 8).
Clean (mvn clean) and re-build project.
This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 6 years ago.
I am not a Java programmer really, so I am posting this question. The exception is being thrown java.lang.UnsupportedClassVersionError in my main class in an eclipse project. If I comment out the imports that this class has, it compiles and runs fine. If I put the imports back in, it does not work. Does this mean that the libraries I am importing were compiled with a newer or older version of java than I have? when i do java -version on the system i get 1.5_07
I could've sworn this was actually working last week, but maybe some setting in eclipse got tweaked? Is the Java Build Path in eclipse what I need to look for to check the JRE and compiler versions?
In Eclipse, the compiler version is set independent of the JRE version. That means you can set the compiler to Java version 1.6 and use the JRE 1.5. In this case, you compiled classes cannot be run.
You can check the preferences in Window / Preferences / Java / Compiler for the default compiler compliance level, or the properties of your project for a project specific compiler compliance level. Compare that level with the JRE used in your project (Project / Properties / Java Build Path -> Libraries / JRE System Library) and in your program's launch configuration (via the Run / Run Configurations... menu).
UnsupportedClassVersionError means that the Java runtime environment you are using doesn't recognise the version of a class file that you are trying to execute. The most common cause for this error is trying to use a class file compiled for a newer Java version on an older Java version - for example, you are trying to use a class compiled for Java 6 on a Java 5 runtime environment.
As Eugene explained, Eclipse has its own built-in compiler, it does not use the compiler from the JDK - so that's how you can end up with Java 6 class files even if you're running on Java 5.
Christian explains how to set the Java class file version in Eclipse.
Eclipse is not using JDK compiler, but has its own compiler which can produce bytecode for any JRE. You need to make sure that compiler settings in your project are set to the same or lower version as the JRE you have registered in Eclipse. See Window / Preferences / Java / Installed JREs and also check what JRE is used in your launch configuration (see Run menu for that).
If your imported classes come from an external library (i.e., not compiled from sources within your project), then you should validate that the JRE used for your project is new enough for this library.
If you are using Maven with Eclipse, you can use the Maven plugin to update the project and then do a Maven "clean" . This resolved a goofy and unexpected show of this error in my case.
I know this is an OLD thread now but I had a recent adventure with this type of error.
When trying to compile my project within Eclipse using an Ant build file.
Eclipse Kepler (Java 1.7)
Ant 1.7
Project = Java 1.5
All internal paths and compiler settings were amended to look at Java 1.5 and the project built fine in Eclipse.
When trying to compile using Ant I got the java.lang.UnsupportedClassVersionError in eclipse and began looking around - including on here and finding this page.
My resolution was this :
Windows > Preferences > Ant > Runtime > Global Entries
Global Entries was pointing at the Java 1.7 tools.jar
I added a new External Jar (on the right menu) and pointed it at the Java 1.5 tools.jar
I removed the original entry (for 1.7 tools.jar) and my ant builds started working.