2012-04-30 11:28:24 8 Comments

I am trying to use Notepad++ as my all-in-one tool edit, run, compile, etc.

I have JRE installed, and I have setup my path variable to the .../bin directory.

When I run my "Hello world" in Notepad++, I get this message:

java.lang.UnsupportedClassVersionError: test_hello_world :
 Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)

I think the problem here is about versions; some version of Java may be old or too new.

  1. How do I fix it?
  2. Should I install the JDK, and setup my path variable to the JDK instead of JRE?
  3. What is the difference between the PATH variable in JRE or JDK?


@Seifedine Tamallah 2019-01-13 18:08:05

make sure you check Environment variables versions of java , it could be just the difference between the versions of JAVA_HOME (JDK path) and JRE_HOME (JRE path) , that cause the problem

@Eric Wang 2019-01-08 13:45:39

Since java 9 -target is replaced by --release.

Till java 11, the available numbers for --release are 6 7, 8, 9, 10, 11.
And you can guess the future versions will be 12, 13, and go on.

To compile for an older target jvm:

javac --release 7 // this will generate .class file that could run on jvm >= 7,

Then you can check the target version via:

javap -v Tmp | grep version

in the output, major version identify the target jvm version.

  • 55 -> java 11
  • 54 -> java 10
  • 53 -> java 9
  • 52 -> java 8
  • 51 -> java 7
  • 50 -> java 6

Future version will remove more older versions:

  • As of java 11, major versions <= 49 (java version <= 5), are not supported.
  • As of java 12 and 13, major versions <= 50 (java version <=6), are not supported.

You can find out which target versions are support by current javac, via command:
javac -help | grep releases

@Siddharth Choudhary 2018-11-10 01:47:15

The answer is for the problem:

Exception in thread "main" java.lang.UnsupportedClassVersionError: edu/stevens/cs549/dhts/main/LocalContext : Unsupported major.minor version 52.0

I was having the same problem. For those who were having this trouble in AWS ec2 instances, and have somehow got redirected here to this question. I am answering for those, and would like to share that how I did it. I was having the trouble because Amazon EC2 instances were running java version 1.7 and maybe my project was not compatible with it because I was using Maven and it kind of preconfigured for java 1.8. So I installed new version of java:

sudo yum -y install java-1.8.0

And then the important step is to remove the older version:

sudo yum remove java-1.7.0-openjdk

Remember to delete it after installing the new version, else it would continuously be using the same older version and I hope it resolves your problem, which did in my case.

@Juha Palomäki 2012-07-11 11:59:50

The version number shown describes the version of the JRE the class file is compatible with.

The reported major numbers are:

Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

(Source: Wikipedia)

To fix the actual problem you should try to either run the Java code with a newer version of Java JRE or specify the target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions.

For example, in order to generate class files compatible with Java 1.4, use the following command line:

javac -target 1.4

With newer versions of the Java compiler you are likely to get a warning about the bootstrap class path not being set. More information about this error is available in blog post New javac warning for setting an older source without bootclasspath.

@Andrew Thompson 2013-01-10 05:31:05

"The version number shown describe which version if Java was used to compile the code." No it does not. It shows the version of the JRE that the class file is compatible with. Using cross-compilation options you can use a 1.7 JDK to compile code with a class version of 1.1 (through 1.7).

@Jonathan Leung 2013-03-05 12:58:58

This answer does not explain how to fix it as the question asked?

@Alphaaa 2013-05-23 14:03:10

This is a nice solution for compiling to a previous version from Eclipse directly:

@Sam 2013-09-25 14:58:30

IN eclipse project=>Proerties=>java compiler; set "the compiler compliance level" to the version according to your jre or jdk. As for me, it's 1.6 for jre 1.6

@Gana 2014-12-22 06:22:39

This may occur when compiler source is set in non-compliance with currently compiling JRE/JDK. For example i found the below values from eclipse .settings folder, org.eclipse.jdt.core.compiler.compliance=1.7, org.eclipse.jdt.core.compiler.source=1.7, org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7. And my compiler was 1.6.0_32. The problem was resolved after changing the values to 1.6. The issue originated after i copied the project from a different workspace where i was using JDK 1.7 :(

@Kimchi Man 2017-01-27 19:25:14

On eclipse, right click on the project -> click properties -> click Java Build path on the left panel -> Click Libraries tab -> change the 'JRE System Library' to the right version

@Youness 2017-06-29 18:34:21

Use the following link if you are compiling with maven (to set maven.compiler.source and properties):… 2017-12-04 03:32:58

Worked solution.When I cjanged my jdk version from1.7 to 1.8.Thankyou verymuch Juha Palomäki .You saved my time

@StrongYoung 2018-06-19 08:22:24

you can specify the "target" for the compiler in the build.xml file, if you are using ant, just like below:

 <target name="compile" depends="init">
    <javac executable="${JAVA_HOME}\bin\javac" srcdir="${src.dir}" target="1.6" destdir="${classes.dir}" debug="true"
        deprecation="true" classpathref="compile.classpath" encoding="utf8">
        <include name="**/*.java" />

@Thamme Gowda 2014-03-10 11:01:51

If you're facing this issue while using Maven, you can cross compile your code using the plug-in Maven Compiler.


UPDATE: set source and target to 1.8, if you are using JDK 8.

@coding_idiot 2014-11-01 09:39:13

a snippet on how to use the plugin to cross-compilte would be very good instead of visiting/opening the link

@Mike-Bell 2018-03-06 12:29:48

In my case the problem was in the server runtime configuration:

Server Runtime Environment

Check the JRE is the version you need:

enter image description here

The project was in version 1.7 and the server JRE was set as 1.6, after changing to the proper java version it launched fine.

@kenorb 2015-04-04 12:16:11

The most common issue is misconfiguration of your JAVA_HOME variable which should point to the right Java Development Kit library, if you've multiple installed.

To find where SDK Java folder is located, run the following commands:

jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));'


To check which java (openjdk) you've installed, check via:

dpkg -l "openjdk*" | grep ^i


update-java-alternatives -l

To change it, use:

update-alternatives --config java

Prefix with sudo if required.

to select the alternative java version.

Or check which are available for install:

apt-cache search ^openjdk

Prefix with sudo if required.

Then you can install, for example:

apt-get install openjdk-7-jre

Prefix with sudo if required.

Fedora, Oracle Linux, Red Hat

Install/upgrade appropriate package via:

yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel

The java-1.7.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.7.0-openjdk-devel package.


There is an OpenJDK 7 package in the FreeBSD Ports collection called openjdk7 which probably needs to be reconfigured.

See: OpenJDK wiki page.


Just install appropriate Java SE Development Kit library from the Oracle site or install


If you're experiencing this issue with Jenkins, see:

However selecting the right version of Java (newer) with update-alternatives should work.

@Alter 2017-11-24 23:16:01

This answer worked for me when trying to use spark2-shell on a host after adding the spark service to a cluster with cloudera.

@Philip Rego 2017-07-18 00:03:14

I tried everything. Reinstalling Tomcat is what finally worked. Here's what I've checked before reinstalling.

Make sure your environmental variables look like this.

$ echo $JAVA_HOME
C:\Program Files\Java\jdk1.7.0_51\
$ echo $JRE_HOME
C:\Program Files\Java\jdk1.7.0_51\jre\bin

Make sure Eclipse is using the same jre you set JAVA_HOME to (if JAVA_HOME is not set it will look at JRE_HOME). Window > Prefrences > Java > Installed JREs (the checked one is the default one)

If you made any changes to any of your tomcat files especially catalina.bat or startup.bat, then you may be telling tomcat to look at a different version of java than the one you set to JAVA_HOME C:\Program Files (x86)\Apache\apache-tomcat-7.0.26\bin

@Mohammed Safeer 2017-03-18 17:43:53

I have faced the same problem, and I fixed it in Linux.

Check your $JAVA_HOME

Need JDK 1.8 to compile/build APK

Install Java JDK 1.8 and change the JAVA_HOME

Edit ~/.bashrc and add your JDK 1.8 path as JAVA_HOME.

export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre/

And source ~/.bashrc

Close the current terminal window/tab and run $JAVA_HOME to check the path.

@Manohar 2016-09-13 16:08:19

Your Java file is compiled with a different version (higher compiler version) than the version (lower runtime version) you are trying to run it with.

It is basic understanding that classes compiled with lower versions are expected to run in the later higher versions. But the opposite (compiled with higher compiler version and trying to run it with lower runtime version) is quite not possible sometimes.

Hence you are shown this error, when trying to execute your program. Unsupported major.minor version x.x

Q: I have created an application in Java 7, but when my users try to run it they get an Unsupported major.minor version 51.0 error. What does this mean and what can I do about it?

A: If you compile an application using javac in Java 7, the resulting classfiles will have the 51.0 version number. Versions of Java prior to 7 do not recognize this number, so your users will have to upgrade to Java 7 prior to running your application. If you are not using any Java 7 APIs you can try to compile your application using javac -target 1.6 to create a 1.6-compatible classfile. If your application is deployed using webstart you can specify the minimum version required. For more information, see the docs on Java Web Start and JNLP here. This issue will go away once we trigger autoupdate to Java 7 for end-users currently having Java 6 on their desktops. The timeline for this is not yet determined, we want to give developers time to work out any issues between their code and JDK 7 first.


@lilalinux 2016-07-20 08:18:27

I'm using OS X v10.11.5 (El Capitan), and I tried setting JAVA_HOME and forcing the "correct" Java version via Maven. Nothing helped.

The problem happened when the OS X account was logged out while the application was still running. After logging in again, OS X opened the old terminal session with greyed-out history. I used the same terminal session to build the project, but failed with the unsupported class version error.

Cleaning the Maven project didn't help at all.

To solve the problem, I simply had to close the auto-opened terminal window and use a new one.

@ethemsulan 2015-11-03 08:03:53

  • If you use Maven, set your Java compile level. Open a command line and write java -version for your compile level:

    Enter image description here

  • If you use IntelliJ IDEA, select project → FileSettingsBuild Execution DeploymentCompilerJava Compiler. Then change byte code as 1.7 like this image:

    Enter image description here

@Joe Borysko 2016-09-22 19:15:44

I needed to do a maven clean install as well after changing the pom.

@antonkronaj 2015-11-01 00:35:58

I solved this issue for me by checking that Maven Dependencies were being deployed in Deployment Assembly. In my case they were not.

Adding it fixed the problem.

@George 2015-09-01 08:34:44

Add this to your pom.xml file:

<project ....>

Where 1.7 is the Java version you intend to use. This overwrites the Maven compiler setting, so it's good to debug from here.

@webtweakers 2015-08-04 09:45:23

Yet another way to fix this on Mac OS X with Homebrew installed, is this:

brew install Caskroom/cask/java

@Bhuwan Gautam 2015-04-18 12:21:02

I got the same issue with Spring Source Tool (STS) IDE for a Grails project. I checked the installed Java version and the project Java version were 1.7.*. Later I found that in GGTS.ini file the Java version was set to 1.6:


-Dosgi.requiredJavaVersion=1.6 changed to
Add below two lines before -vmargs

Problem solved. Happy coding.

@snowfi6916 2017-01-19 15:59:28

For me, I was getting this error on the com/sun/javadoc/Doclet class. After some digging, I found that I accidentally copied the tools.jar from Java 8 into my Java 7 folder.

Finding the tools.jar for Java 7 and putting it back into the folder fixed my issue. So something to try.

@Vihung 2015-03-26 09:42:12

How do I fix it?

This error means that the JRE that is being used to execute your class code does not recognise the version of Java used. Usually because the version of Java that generated your class file (i.e. compiled it) is newer.

To fix it, you can either

a) Compile your Java sources with the same, or older, version of the Java compiler as will be used to run it. i.e. install the appropriate JDK.

b) Compile your Java sources with the newer version of the Java compiler but in compatibility mode. i.e. use the -target parameter.

c) Run your compiled classes in a JRE that is the same, or newer, version as the JDK used to compile the classes.

You can check the versions you are currently using with javac -version for the compiler, and java -version for the runtime.

Should I install the JDK, and setup my PATH variable to the JDK instead of JRE?

For compilation, certainly, install and configure the specific JDK that you want.

For runtime, you can use the one that comes with the JDK or a standalone JRE, but regardless, make sure that you have installed the right versions and that you have configured your PATH such that there are no surprises.

What is the difference between the PATH variable in JRE or JDK?

The PATH environment variable tells the command shell where to look for the command you type. When you type java, the command shell interpreter will look through all the locations specified in the PATH variable, from left to right, to find the appropriate java runtime executable to run. If you have multiple versions of Java installed - i.e. you have the java executable in multiple locations specified in the PATH variable, then the first one encountered when going from left to right will be the one that is executed.

The compiler command is javac and only comes with the JDK. The runtime command is java and comes with the JDK and is in the JRE.

It is likely that you have one version (51.0 = Java 7) of javac installed, and you also have the same version of java installed, but that another previous version of java is appearing earlier in the PATH and so is being invoked instead of the one you expect.

@AmazingDayToday 2016-10-12 21:54:43

  1. Click Properties in a project.
  2. Go to Java Build Path.
  3. Click Add Library.
  4. Click Next on JRE System Library. Select the one you need if not selected by default.
  5. Click Finish.

You're done!

@Luigi04 2016-07-16 23:58:14

If you have a second project added to your build path make sure it has the same compiler version as your first one: Properties -> Java Compiler -> Compiler compliance level

@Mace Ojala 2013-09-16 18:25:12

As answered elsewhere by several people, the Java program is being run on an older version of Java than the one it was compiled it for. It needs to be "crosscompiled" for backward compatibility. To put it another way, there is a mismatch between source and target Java versions.

Changing options in Eclipse menus don't answer the original poster, who said he/she is not using Eclipse. On OpenJDK javac version 1.7, you can crosscompile for 1.6 if you use parameters -source and -target, plus provide the rt.jar -file of the target version (that is, the older one) at compile time. If you actually install the 1.6 JRE, you can point to its installation (for example, /usr/lib/jvm/java-6-openjdk-i386/jre/lib/rt.jar on Ubuntu, /usr/jdk/jdk1.6.0_60/jre/lib/rt.jar on SunOS apparently. Sorry, I don't know where it is on a Windows system). Like so:

javac -source 1.6 -target 1.6 -bootclasspath /usr/lib/jvm/java-6-openjdk-i386/jre/lib/rt.jar

It looks like you can just download rt.jar from the Internet, and point to it. This is not too elegant though:

javac -source 1.6 -target 1.6 -bootclasspath ./rt.jar

@Andreas L. 2013-08-06 10:24:19

In Eclipse's menu Window -> Preferences -> Java -> Compiler check also "Configure Project Specific Settings".

If you stil have the error with same Java version: try to delete build folder of your project manually. Then restart Eclipse.

@TomTom 2015-04-09 09:10:19

Oh Mac OS X I was able to solve this problem by setting the JAVA_HOME variable:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home

@Tony 2014-02-11 06:55:26

I had a similar situation on Mac, and the following process worked for me:

In the terminal, type

vi ~/.profile

Then add this line in the file, and save

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk<version>.jdk/Contents/Home

where version is the one on your computer, such as 1.7.0_25.

Exit the editor, then type the following command make it become effective

source ~/.profile 

Then type java -version to check the result

java -version 

What is .profile file?

.profile file is a hidden file. It is an optional file which tells the system which commands to run when the user whose profile file it is logs in. For example, if my username is bruno and there is a .profile file in /Users/bruno/, all of its contents will be executed during the log-in procedure.


@mariusz117 2014-11-28 13:59:33

I had the same situation but any of above tips didn't help :) In our environment we had tomcat running as a service on Windows. We installed Java 1.7 and set up JAVA_HOME on this version. Off course the sources were built on Java 1.7. Nevertheless the tomcat said that it use previous version of JVM. After a deep analized turn out that the Tomcat service installed on Windows still keeping the old value for JAVA_HOME pointing to Java 1.6. After installing new Tomcat service everything were resolved. So the conclusion is: When you change java version and tomcat running as a service, you have to reinstall tomcat service.

@Brad Parks 2013-02-20 19:02:45

This error means you're trying to load a Java "class" file that was compiled with a newer version of Java than you have installed.

For example, your .class file could have been compiled for JDK 7, and you're trying to run it with JDK 6.

So the solution is to either:

  • Upgrade your Java runtime or
  • Recompile the class if you have the source, using your local Java compiler (if you have one).


For developers, this can happen if another developer checks in a .class file, and they've got a newer version of java than you have!

@Chris 2015-02-12 18:31:57

Except inside jars.

@siddmuk2005 2014-08-04 10:21:55

  • Install JDK 7.0.55 and set the Java for Eclipse for JDK 7.0.55.
  • Build the project with JDK 7.0.55 by configuring on build path JDK 7.0.55.
  • Set the compiler in Eclipse for JDK 7.0.55 by menu Windows -> Preferences -> Java -> Compiler - choose 1.7.

@Siddharth 2014-08-22 03:53:52

I solved it. I ran:


The error is misleading, Unsupported major.minor version 51.0. This gives the impression that version 51 (Java 7) is not supported. And we should use Java 6.

The error should have been:

The current Java version, 50, is unsupported. Use Java version 7 (51:0 and greater) instead.`

@Ben 2014-09-01 08:02:28

I got the same problem with a project written in 1.7 and tried to execute in 1.6.

My solution in Eclipse:

  • Right click on your Project Properties -> Java Build Path -> Libraries

  • Select your JRE System Library and click Edit on the right, and choose the target JRE.

  • Now go to Java Compiler on the left, and change the Compiler compliance level to your target.

That worked for me.

Related Questions

Sponsored Content

26 Answered Questions

[SOLVED] Unsupported major.minor version 52.0

50 Answered Questions

[SOLVED] How do I fix android.os.NetworkOnMainThreadException?

12 Answered Questions

[SOLVED] Why is Ant giving me a Unsupported major.minor version error

  • 2011-08-16 03:54:55
  • coder
  • 110222 View
  • 42 Score
  • 12 Answer
  • Tags:   java eclipse ant

7 Answered Questions

3 Answered Questions

[SOLVED] File reading using OpenCSV

1 Answered Questions

Unsupported major.minor version 52.0 Error

1 Answered Questions

[SOLVED] JasperReports: Unsupported major.minor version 51.0

Sponsored Content