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.
Related
Following the solutions online for Major Minor version of Java being incorrect on El Capitan, I saw several solutions which made you either disable rootless, which i didn't like the sound of, or just didn't work anymore in OS X El Capitan.
When trying to run webdriver-manager start on El Capitan, you may get an error saying:
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
The recommended fix for this online is to change the symlink that Mac OS X has to Java, which you can find by running echo $JAVA_HOME in the terminal.
This is pointing to the incorrect folder, and the error is because the application was compiled with a higher version of JRE than the machine is running in the terminal.
You should go to Oracle, and download the latest JRE version (http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)
After this has been installed, you will have Java 8 on your machine, but it will not update the terminal properly. If you run java -version in your terminal, you'll see Java Version "1.6", you want this to say Java Version "1.8". The previous way to do this was to change the symlink manually, however, since El Capitan, Apple have made certain folders unchangable even to admin users, with their Rootless install. This includes the /usr folder.
There are two ways to fix this, the first is dangerous, and what everyone else seems to recommend. The second, is safer, and what I am putting here.
If you go to your System Preferences -> Java -> Java -> View... -> System and copy the Path field.
It will look something similar to the following:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
We want most of this path, except the /bin/java on the end.
So your path should now be copied as:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Run the following command in the terminal, replacing [PATH] with the path you have from above.
export JAVA_HOME="[PATH]"
and run that in the terminal.
Afterwards, run java -version again, and it should now say Java Version "1.8"
Now, webdriver-manager start should succeed.
Adding the following line to ~/.bash_profile worked for me:
export JAVA_HOME="$(/usr/libexec/java_home --version 1.8)"
You might have to restart your shell for these changes to reflect or just run:
. ~/.bash_profile
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'm fully aware that this question has already been asked in a way in this thread:
Cassandra:UnsupportedClassVersionError
However, the answer/s given there, which I accept, don't solve my problem as I do have a current version of Java as detailed below:
D:\Development\Cassandra\apache-cassandra-2.0.6>java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Client VM (build 24.45-b08, mixed mode, sharing)
Knowing this, I still receive the error when starting Cassandra:
D:\Development\Cassandra\apache-cassandra-2.0.6>bin\cassandra -f
Starting Cassandra Server
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/cassandra/service/CassandraDaemon : 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: org.apache.cassandra.service.CassandraDaemon. Program will exit.
I'm running on a Windows XP machine using the command prompt (not Cygwin) to start Cassandra and I'm able to start older versions of Cassandra without any issue (apache-cassandra-1.1.4). Am I doing something incorrect with the later version of Cassandra or have I missed something somewhere in my configuration that is blindingly obvious?
The only plausible explanation for that exception is that a Java 6 (or earlier) JVM is being use to run code that was compiled for the Java 7 target platform.
This contradicts what you believe to be happening. Nevertheless, it is the only plausible explanation.
I suggest that you make a copy of the cassandra wrapper script (in the same directory), and hack it to:
add set -x at the start to see what commands are actually being run by the script.
add echo $PATH, echo $JAVA_HOME and so on to see what the key environment variables are in the script's environment.
add a line to run java -version using the exact same command path that is being use to run the JVM for real.
This should reveal which of your beliefs / assumptions about what is happening are incorrect.
I did try with uninstalling java 1.7 and installing the latest java 8 got solved my issue.
I have a Jar which is running in fine in eclipse and cmd prompt.
When i tried executing the same in Unix , it is not executing.
Note: Java version in Unix is 1.5 ; Java version in eclipse is 1.7
java -jar text.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad
version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
You answered the question yourself. While compiled at 1.7 you try to execute the jar in an 1.5 environment. Update your Unix JRE to 1.7 and it should work.
Alternatively you can rebuild the jar at 1.5. In eclipse, right click at your project in the project browser => properties => java compiler => compiler compliance level.
You get the UnsupportedClassVersionError when you are trying to run an application having a jar in the classpath that is built using a newer version than the one you are using at runtime.
You get this error when you try to run a class that was compiled for a Java version newer than what you have; for example, if you try to use a class that was compiled for Java 6 or newer on a Java 5 JVM.
It doesn't necessarily have to be your own class; you might be using some library that was built for Java 6 or newer.
Are you using specific libraries (JAR files)? Check if these are compatible with Java 5 or not. Or upgrade your Java version to Java 6