Unsupported major.minor version 51.0 Issue - java

I'm using Tomcat 7.0.26 in my ubuntu server, I've installed Oracle JDK and here is the output of
java -version command
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
And output of javac -version command is :
javac 1.7.0_51
I didn't specify JAVA_HOME and JRE_HOME manually and I've installed JDK from ppa:webupd8team repository.
And in my windows machine I export my web project to war file with Eclipse and compiler version of it is 1.7, I checked it in Properties of my project, in Java Compiler section, configuration is below :
Use compliance from execution environment 'JavaSE-1.7' on the Java Build Path
In Installed JREs section in my Eclipse, default one is JDK 1.7.0_45. I also checked major version of my compiled java classes with
javap -verbose MyClass | findstr "major"
command and it is 51. But I get this exception below from Tomcat in ubuntu :
java.lang.UnsupportedClassVersionError: com/maozturk/MyClass : Unsupported major.minor version 51.0
Why am I getting this exception since version of them are same?

I still don't know exactly what problem is but it solved when I upgrade Tomcat to 7.0.52.

I know that topic is about Tomcat, but I had the same problem with Glassfish, maybe it could be helpful - I've changed java version for Glassfich to java 1.8 (after install it :) )

Related

Java appears to be outdated when using java -jar command

I have recently been writing some Java programs on my Windows computer. I have been trying to use java -jar to run compiled jars in order to see errors more clearly, but when I try to do this, I get the following error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/company/app/GUI has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0
This obviously means that my java version is outdated. However, when I took a look at the Java Updater, it shows that I am running the latest version.
Running java -version shows this:
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) Client VM (build 25.261-b12, mixed mode)
So why is Command Prompt using an older version, and how do I change it?
Thank you for your help.
This error clearly indicates that you try to run a .jar file built with JDK 13 (major version 57) on a JRE/JDK 8 (major version 52) which is provided in PATH setting and thus invoked when running java -jar / java -version commands.
If you have JDK 13 installed on your machine, you need to check environment variable PATH and/or JAVA_HOME:
C:\Users\hp1>echo %JAVA_HOME%
C:\Java\jdk-13.0.2
C:\Users\hp1>echo %PATH%
C:\Windows\system32;C:\Java\jdk-13.0.2\bin
C:\Users\hp1>java -version
openjdk version "13.0.2" 2020-01-14
OpenJDK Runtime Environment (build 13.0.2+8)
OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
If PATH refers JRE/JDK 8, you may create another variable and update PATH (copy non-java paths):
>set JAVA_13=**path_to_your_jdk_13**
>set PATH=C:\Windows\system32;%JAVA_13%\bin
If you do not have JDK 13 on your machine, to resolve this issue you should rebuild the .jar file to make it compatible with JDK 8 providing that the code is not using any features from the newer versions.

Java + Selenium

Basic configurations:
Docker container for My PHP instance, I installed Centos and inside java, then Selenium but when I try to start it, it gives me an error.
[root#6f0958965698 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root#6f0958965698 ~]# java -jar /opt/selenium-server-standalone.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/grid/selenium/GridLauncherV3 : Unsupported major.minor version 52.0
[root#6f0958965698 ~]# java -version
java version "1.7.0_191" / OpenJDK Runtime Environment (rhel-2.6.15.4.el7_5-x86_64 u191-b01)/ OpenJDK 64-Bit Server VM (build 24.191-b01, mixed mode)
I tried first with the version http://selenium-release.storage.googleapis.com/3.9/selenium-server-standalone-3.9.0.jar
and then with: http://selenium-release.storage.googleapis.com/3.2/selenium-server-standalone-3.2.0.jar
Same mistake.
Do you have any suggestions?
Exception in thread main java.lang.UnsupportedClassVersionError is thrown because the jar is compiled with higher version of Java and trying to run with lower version.
Please refer to this answer: How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
Ex:
Compiled with JDK 1.8
But you run it JDK 1.7, so this throws the exception.
Just update the java version to JDK 1.8 in your container and run again.

Unsupported major.minor version 51.0 (org/apache/maven/cli/MavenCli) - MAC OS X

This is my java version: java -version
java version "1.8.0_20" Java(TM) SE Runtime Environment (build
1.8.0_20-b26) Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
And my bash_profile:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
M2_HOME=/Users/michaelkees/apache-maven-3.3.9
M2=/Users/michaelkees/apache-maven-3.3.9/bin
PATH=/Users/michaelkees/apache-maven-3.3.9/bin:/Users/michaelkees/Documents/apache-maven-3.3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/sbin
Maven 3.3.9 is installed
When I try to use the command : 'mvn -v'
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
Go to Run configuration and choose Java 7 or Java 8 for maven version above then 3.2.X
Maven 3.3 required higher Java version.
Is you output of your .bash_profile what you have posted? If so than you need to change it cause the environment variables will not made available to sub processes. You need to use the following in your .bash_profile:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
export PATH=/Users/michaelkees/apache-maven-3.3.9/bin:$PATH
After you have changed it you need to make a new login.
An other approach is to define JAVA_HOMEĀ“ via.mavenrc` file which might be a little bit more flexible.
You need to create a file .mavenrc in your home directory $HOME/.mavenrc which contains a line like this:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
Than you don't need to define JAVA_HOME in your .bash_profile.

Weblogic 12c deployment error : unsupported classversion 52.0

I'm trying to deploy an EAR file to WebLogic Server Version: 12.1.1.0 but it gives me this error:
weblogic.management.DeploymentException:
Error mydirectory/weblogic/LifeCycleListener : unsupported classversion 52.0
LifeCycleListener is a .java file. Here is the Java version I have installed on my machine, and with which i compiled the EAR file:
C:\Users\USER>java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) Client VM (build 25.11-b03, mixed mode, sharing)
javac 1.8.0_11
why is this happening? i have the JDK up to date and everything..is there any code I can put in the java file or any solution?
You compiled your code with Java 8, but your Weblogic server is running an older Java version.
Either compile your code using the Java version of your target server, or upgrade your server's Java engine to Java 8.

Failed to install jdk 1.7 on mac

I'm trying to install JDK 1.7 update 21 on Mac OSX 10.7 .
I downloaded the installer from oracle site (as dmg file). ran the installer which completed successfully.
Now I can't find the java SDK anywhere on the file system.
The output of /usr/libexec/java_home -V is :
***/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home***
which is the previous version installed.
also running java -version executes the same old version.
***Java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)***
In the java control panel I do see that the JRE has updated to Java 1.7 for the browser but there aren't any details regarding the JDK there.
Where can I find the new JDK on the file system and how do I set it as default ?
Is there any log file for the installation that I can use to debug ?
Try adding this to your shell startup script (.bash_profile off of ~ if you are using bash):
export JAVA_HOME=`/usr/libexec/java_home -v '1.7*'`
The changeover from Apple providing the JDK to Oracle has been a complete disaster.

Categories