Venter C.
—You get the following error when trying to run your Java program:
java.lang.UnsupportedClassVersionError: Unsupported major.minor version
A major.minor
version error occurs when the Java Runtime Environment (JRE) version used to run a program is older than the Java Development Kit (JDK) version used to compile its code. You can resolve this by:
If you have access to the compiled .class
or .jar
files, use the following command to check the version they were compiled with:
javap -verbose MyClass | grep "major"
You will see an output like:
major version: 61
Ensure the JRE running your application is at least as recent as the JDK used to compile the code. For example, if the class is compiled with Java 17 (major version 61), you need to run it with Java 17 or higher.
java -version javac -version
If the java
version is older than javac
, install the appropriate JDK or JRE version, or update your Java version.
If you need to run the code on a system with an older JRE, you can recompile your Java code with compatibility flags to generate bytecode compatible with older versions.
The following command compiles the code to be compatible with Java 8 (major version 52):
javac --release 8 MyClass.java
JAVA_HOME
and PATH
Ensure that your environment is configured to use the correct version of Java by setting JAVA_HOME
and PATH
.
On Linux/macOS:
export JAVA_HOME=/path/to/your/java export PATH=$JAVA_HOME/bin:$PATH
On Windows (CMD):
set JAVA_HOME=C:\path\to\your\java set PATH=%JAVA_HOME%\bin;%PATH%
If the code requires a specific version, download and install it from the official Java website or an open-source distribution like AdoptOpenJDK.
If you are using an IDE like IntelliJ IDEA or Eclipse, make sure the project settings are configured to use the correct JDK version.
Each version of Java assigns a unique major.minor
version number to compiled class files, so running any class with a newer major version on an older Java virtual machine will return major.minor
version error.
UnsupportedClassVersionError
documentationTasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODESConsidered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).
×We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.
Am I included?We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII:
If you have any questions or concerns about your privacy at Sentry, please email us at compliance@sentry.io.
If you are a California resident, see our Supplemental notice.