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.
Related
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.
I'm doing this project where I have a webservice done in Java (HttpServlet) that uses Hibernate to select, insert and update information into a database and return an array of objects as JSON to whoever connects to the JSON endpoint.
I created it on my local computer and it works fine. However, I'm now trying to see how it would work on an actual server instead of locally.
So I connected through SSH to the server and copied the .war build to the Tomcat webapps folder, tried to run it, then I got the below error:
javax.servlet.ServletException: Servlet execution threw an exception
root cause java.lang.UnsupportedClassVersionError: org/hibernate/HibernateException : Unsupported major.minor version 52.0 (unable to load class org.hibernate.HibernateException)
So naturally I looked on StackOverflow to see what this error is about and I found that it's when you create your project in one version of Java and try to run the project on an inferior java machine. And I did that, indeed.
I created my project using Java 8 and I was running it on Java 7, on the server. So I updated the server to use Java 8. However, after updating to Java 8, I still get the same error.
If I run the java -version command, here's what I get:
LOCAL COMPUTER:
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
SERVER:
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
As you can see, I have java 1.8.0_121 on my local machine and java 1.8.0._111 on the server. Do you think there's any chance that that is the problem? Aren't they both Java 8?
Also, how does Tomcat know which java to use? I have 3 versions on the server (2 versions of the Java 7 and one version of the Java 8, java 1.8.0_111). How does Tomcat know which one to use?
To choose which one to use I used the sudo update-alternatives --config java command and chose the 1.8.0_111 version from there (the server is Ubuntu 12.04).
The problem is - I keep getting that error: java.lang.UnsupportedClassVersionError: org/hibernate/HibernateException : Unsupported major.minor version 52.0 (unable to load class org.hibernate.HibernateException) - and I can't run my project on the server.
Any suggestions?
When I got this error few days back, I had different versions of JDK and JRE running on my machine. I rectified it by setting the correct JRE path in Project's Build Path and also in the Window Preferences->Java->Installed JRE's. Also if you go to setenv.bat in your Tomcat\bin, there you specify which version of java should the Tomcat use by specifiying this:
set "JRE_HOME=%ProgramFiles%\Java\jre1.8.0_121", (obv, your version might be different so change that accordingly).
I hope that answers your query!
Edit: If you are wondering what setenv.bat is, refer: https://docs.oracle.com/cd/E40518_01/integrator.311/integrator_install/src/cli_ldi_server_config.html it explains what this bat file should contain.
As per the Documentation,
Hibernate 5.2 and later versions require at least Java 1.8 and JDBC 4.2.
Hibernate 5.1 and older versions require at least Java 1.6 and JDBC 4.0.
When building Hibernate 5.1 or older from sources, you need Java 1.7 due to a bug in the JDK 1.6 compiler.
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.
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 :) )
I have downloaded a web application project onto my Mac OSX 10.8.2 and I am using the Apache ant to compile it. I am getting this error when the application is running, attempting to compile-and-execute a JSP:
javax.servlet.ServletException: java.lang.UnsupportedClassVersionError
Unsupported major.minor version 51.0
I have searched for this problem on the web, and it seems this problem is caused by the compiled version being different from the running version of Java. All the suggested solutions are to "set the compiler version in Eclipse," but I am not using Eclipse...
This is my environment:
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
How can I check the ant-compiled version(s) of my class files and resolve this problem?
This problem is because you have compiled the code on a higher version of java and then running the code on a lower version of java. Usually the servers ship with their own version of JVM. So one way to find the jvm used by your server is to check the startup logs of your server. It should show the jvm version.
UnsupportedClassVersionError is mainly because of the java version mismatch between running and compile versions .
Both versions should match in order to avoid the error GO through the below link to get more details about the ant version change.
Why is Ant giving me a Unsupported major.minor version error