This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Exception in thread “main” java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0)
My Java program which I run on Mac & Windows is not working. Instead I get this error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: menus/Main_Screen : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Does anyone know how to fix this? Thanks.
Class version 51.0 is generated by Java 7.
You're trying to run with an earlier version, probably Java 6.
You need to call the Java 7 version of the java command.
The version used to run NetBeans is set in NetBeans/etc/netbeans.conf.
The version used to build and run a project is set by the project properties.
You can tell NetBeans about a new Java version through the Tools > Java Platforms
Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(
It seems your java runtime version is different (lower) version from compile time version.
The general rule is this.
If take a *.class compiled by a version of Java EARLIER than the JRE, it should work in that JRE.
Because the later JRE is supposed to "know" previous versions of format.
If take a *.class compiled by a version of Java LATER than the JRE, it should not work in that JRE.
Because the earlier JRE is not supposed to know the future versions of format.
In your case the code is simply compiled by the version of Java issued after the version of the JRE.
Related
I wanted to install protractor in order to work with our AngularJS project.
Everything went OK till I ran the command:
webdriver-manager start
...and I got some errors:
seleniumProcess.pid: 5421
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/grid/selenium/GridLauncher : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Selenium Standalone has exited with code 1
Then I understood that I was using the wrong version of java (1.6.0_65).
So Ive got the latest one (1.8)
and basically the problem was that on terminal it would show me the old version. but on my actual computer would show me the latest.
However I tried uninstalling java by running this command:
sudo rm /usr/bin/java
and been getting this, no matter what I do.
sudo rm: /usr/bin/java: Operation not permitted
Has anyone experienced the same thing?
(Using OS X 'El Capitan' as my operating system)
You are using a mac and the default version of Java on mac osx is still Java 6 (Apple stopped producing their own version of Java a number of years ago). So, you need to manually install a more recent version of Java from Oracle to get the latest version.
Download the latest version of Java here. Then, run the downloaded dmg file and follow the instructions to complete the installation.
After installing Java 8, simply re-run webdriver-manager start and you should be good to go.
I have got java 1.7 already installed in my computer(Ubuntu 12.04) and with Java_Home and path properly set.Now I want to install java 1.6 as well because one application I want to use runs only with java1.6.
Here is what I have done so far,
1: I download jdk1.6 and extracted it.
2: Modified the java_home and path to include to point to jdk 1.6.
3: Ran these update-alternative commands
sudo update-alternatives --set java /usr/local/java/jdk1.6.0_45/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.6.0_20/bin/javac
Now when I do java -version, I see correct version and I can also compile properly but I do java className I get the following error
Exception in thread "main" java.lang.UnsupportedClassVersionError: three : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
My path variable looks like this
/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/java/jdk1.7.0_40/bin:/usr/local/java/jre1.7.0_40/bin:/usr/local/java/jdk1.6.0_45/bin:/usr/local/java/jdk1.6.0_45/bin
I read somewhere that if java 1.7 comes before 1.6 in path, there will be a conflict. Could that be the case? In that case,how to remove that from path variable?
you have both jdk 1.6 and 1.7 in your path remove the older version from the path
I have a web app compiled with JRE7 and now i'd like to run it on Tomcat6. When I launch my app I see exception in the logs:
Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
This exception comes from the class that implements ServletContextListener.
Does that mean I have to use Tomcat7 for code compiled with JRE7? Is there a workaround? Any information will be valuable.
You're attempting to run Java 7 bytecode with a Java 6. You need to deploy it to Tomcat 7 or recompile using JDK 1.6. Check what JRE your Tomcat uses. I guess it's Java 6 JVM.
You can find out the server information through its status page:
{running-tomcat-url}/manager/status
On that page you can see the version of Java on which your Tomcat runs
I have been coding with Eclipse and testing the code using Terminal on OS X 10.7.4. When I ran the code with Eclipse, it worked. However, running with terminal gave me the following error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: PacketPrinter : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I checked my java and javac version. They are both 1.7. I have been googling but could not find anything.
You're probably not using the same runtime on the command line as when you launch the program from within Eclipse.
Try executing
java -version
from the command line to see which version of java you're using on the terminal.
(You can also run which java to see exactly which file is being executed.)
It seems you have a different version of java running in eclipse and in your terminal.
Do the following:
In the terminal type: java -version
In eclipse goto the preferences and look in Java/Installed JREs
Compare the versions.
Point you $JAVA_HOME and $PATH variables to the same JRE you use in Eclipse.
As aioobe said check you java version using following command
java -version
Copy the contents of the PATH settings to a notepad and check if you have any other java version path present in it and if it is before that of the 7. If so, remove that path in the PATH setting and save it.
I would suggest you to re logging after doing it.
AFAIK this error comes when you have older version java path present in path.
I created a Java application using Netbeans with JDK version as 1.7
Now how do I compile/run the same application on a different machine where JDK 1.5 is installed without making any changes to the code?
When I tried compiling I got an error saying JDK version mismatch.
Given below is the error:
java.lang.UnsupportedClassVersionError: MTPS : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: MTPS. Program will exit.
Changes from one java version to other have different functionality added. Like for example Enum functionality was added since java 1.5 if you try to compile it on 1.4 you get an error.
btw try to compile your app with JDK 1.5, and then if you succeed try to run it.
You need to take care of functionality change in jdk 1.4 to jdk1.6 and jdk 1.6 to jdk 7.
Generic ,Assertion were new implementation in jdk1.5.Some enhancement in Switch case(with String) and Exception handling is new in JDK7.
Code can be compiled for an earlier JRE using the cross-compilation options of javac. If using a 1.7 JDK & targeting JRE 1.5, a 1.5 version rt.jar should be supplied as the boot class path (see docs. for details).