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.
Related
*Due to some project requirements I "have" to use eclipse 4.18 (2020-12) which uses Java 11 by default and is mandatory to start.
But my entire project is/was written in Java 1.7 earlier. Now , in my mac i have both java 1.8 and 11 installed also my eclipse settings are such shown below.
I have made sure removed all java 11 references in my eclipse and made the project and workspace configure to take the 1.8 jdk and run at 1.7 compiler level.*
but when i run ,project -->clean-->build, i run into the JaxB missing in java 11 ( in java 11 JAXB was removed and my project uses jaxB extensively) This is known.
So i am wondering what am i missing that my projects are still building my project with java 11 and not java 1.7 (using jdk 1.8 configured).
Please help.. stuck on this since some days.
machome
Eclipse Compiler setting-1
Eclipse Setting Execution Envs
Eclipse installed JRE's
Eclipse Project specific setting
Java 11 JaxB error
If Eclipse itself is being run with Java 11, and you have a plug-in installed that has not been properly update to work under Java 11, as it appears, you will need an updated version of that plug-in. Update to the latest "oracle design studio", and if you still see this problem, contact Oracle support.
The latest Eclipse may require Java 11 to run, but it's simple to set up Eclipse projects that use older Java versions. Don't mess with the Java version it uses to start up, as long as that is a proper Java 11 version.
As one commenter mentions, you'll have to have a particular Java distribution configured in "Installed JREs->Execution Environments", and then you'll have to have the project configured to use that Java version symbol, like "JavaSE-1.7".
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.
How can I change the Projects Runtime Platform?
(standard NetBeans [8.1] Java Project [Java Application])
Details:
using Ubuntu with NetBeans 8.1
I have installed JDK 1.6, JDK 1.7 + JDK 1.8
My projects platform is Java 6.
My systems default Java is Java 7.
NetBeans-IDE was started with Java 8.
When I run the project via the IDE (Run project), the Project-Platform is used (which is Java 6).
I cannot change the Runtime Platform!
It's always: Project Platform
I tried to Manage Platforms..., but I still can't change the value of the Runtime Platform-ComboBox.
EDIT:
As I wrote in the comments, I don't want to change the Project-Platform.
The project should be compiled with Java 6 but run with Java 8 (when click on Run project).
What I want is:
Project-Platform = Java 6 (used to compile),
Runtime-Platform = Java 8 (used to run).
How can I change the Projects Runtime Platform?
Unfortunately you can't. As you point out, its value can only be Project Platform. Of course that invites the question "What is the point of even having that Runtime Platform field?".
I suspect that it may have been (unwisely) added to the GUI so that at some time in the future it will be possible to actually select a different JDK to run against. There is an open Bug Report for this: Bug 186747 - Can't Build and Run with Different Java Versions.
It's also worth noting that the Help documentation for the Run screen does not mention that Runtime Platform field. My own view is that the field should be removed until it serves a useful purpose.
What I want is: Project-Platform = Java 6 (used to compile),
Runtime-Platform = Java 8 (used to run).
Unfortunately that can't be done, as shown by the open bug. The best you can do right now is:
Create platforms for JDK 6 and JDK 8 in NetBeans.
Set the Java Platform to JDK 1.6 on the Libraries screen, and set the Source/Binary Format to JDK 6 on the Sources screen, then build to verify that no invalid APIs are being used.
Switch the Java Platform to 1.8 on the Libraries screen to run your 1.6 code under 1.8.
I realize that you don't want to do that, but unfortunately there's no silver bullet in the current release of NetBeans (8.2).
An alternative approach would be to build and run using only JDK 8, but include the Animal Sniffer Maven plugin "for checking projects against the signatures of an API", to verify that your 1.6 code was not using illegal APIs. But of course that's only viable for Maven projects.
Please look at Netbeans Project Setup - Setting the Target JDK in a Project
You just have to change the Runtime Platform at the Libraries option, that's all.
Just went through this pain for Apache NetBeans 14. I was trying to set a remote debug for a Raspberry Pi.
It works only if the jdk match on both the local and remote versions. In my case I set them both to 17.
I would have expected that the default jdk on the local machine should have been able to be changed but I fail to determine how.
I am running Ubuntu on the local machine so maybe the platform cannot be changed (don't know). Moving on.
Changed runtime platform
I tried to update my jre version in eclipse,
I added the jre 8 to my installed JRE's an checked him.
When I click OK it gives me an ERROR:
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from
required .class files
It happens only when I am trying to use JRE 8.
Someone know how to fix this?
I use Indigo Eclipse. Version: Service Release 2.
The problem is rt.jar in the JVM 8.0.
java.lang.CharSequence is a class under rt.jar.
rt.jar under JVM 7.0 has no problem, but rt.jar under JVM 8.0 has a problem with Eclipse Indigo. Solition is downloading Eclipse Kepler, JVM 8.0 with Kepler has no problem.
Create new workspace. Create new java project and select jvm8 as jvm. Changing the vm in an existing project is quite difficult and cached class file compiled with the previous vm can generate some strange unpredictable behavior
You need Eclipse Kepler (4.3) Service Release 2. After startup you need to install a patch that enables using Java 8 in eclipse from this update site (Help -> install new Software... -> use site):
http://download.eclipse.org/eclipse/updates/4.3-P-builds/
But a Android Project will not benefit from Java 8 because it still uses Java 6 and you cannot use Lambda Expressions or even the diamond Operator from Java 7.
I'm using Eclipse 3.3. In my project, I've set the compiler compliance level to 5.0 In the build path for the project. I've added the Java 1.5 JDK in the Installed JREs section and am referencing that System Library in my project build path. However, I'm getting compile errors for a class that implements PreparedStatement for not implementing abstract methods that only exist in Java 1.6 PreparedStatement. Specifically, the methods
setAsciiStream(int, InputStream, long) and
setAsciiStream(int, InputStream)
Strangely enough, it worked when we were compiling it against Java 1.4, which it was originally written for. We added the JREs for Java 1.4 and referenced that system library in the project, and set the project's compiler level to 1.4, and it works fine. But when I do the same changes to try to point to Java 5.0, it instead uses Java 6.
Any ideas why?
I wrote a similar question earlier, here:
how do I get eclipse to use a different compiler version for Java?
I know how you're supposed to choose a different compiler but it seems Eclipse isn't taking it. It seems to be defaulting to Java 6, even though I have deleted all Java 6 JDKs and JREs that I could find. I've also updated the -vm option in my eclipse.ini to point to the Java5 JDK.
This isn't about the compiler - it's only about the library! Go to the project's properties, then under Java Build Path / Libraries, remove the JRE System library. Then use Add Library... to add the version of the JRE library you want.