running mvn giving Unsupported major.minor version 51.0 on Mac Os

I just tried running mvn it give the following error :
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(
	at java.lang.ClassLoader.defineClass(
	at Method)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
	at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(

Open in new window

Dont know why this is happening ?
Some details about java and maven :
DDVMACROBINSU:flock-snippets robinsuri$ [b]which mvn[/b]
DDVMACROBINSU:flock-snippets robinsuri$ [b]which java[/b]
DDVMACROBINSU:flock-snippets robinsuri$ [b]ls -l `which java`[/b]
lrwxr-xr-x  1 root  wheel  74 Oct 29  2014 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
DDVMACROBINSU:flock-snippets robinsuri$ [b]java -version[/b]
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Open in new window

Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

UnsupportedClassVersionError is Java's rather unfriendly way of saying, you compiled this code on a newer version of Java than you are trying to run it on.

E.g.  mvn was maybe built using Java 8 and you are now running in on Java 7?

Best solution is usually to upgrade your Java runtime to the latest version.
Rohit BajajAuthor Commented:
my java version as mentioned in the above is 1.7
i think that mean its java 7.
so should i remove it and install java 8 ?
on maven website it mentions that maven 3.3 is compatible with java 7.
thats confusing...
also i dont have the environment variable JAVA_HOME set on my mac.dont know if thats a problem
so should i remove it and install java 8 ?

Yes I think that's what you should do.  Java 8 is the latest anyway, so this is a good step and I think it'll resolve your problems here.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rohit BajajAuthor Commented:
wow upgrading resolved the issue :) thanks a lot

It's really just a very confusing error message from Java - if it said upgrade, it wouldn't be so bad :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.