How to solve javax.servlet.ServletException: java.lang.UnsupportedClassVersionError? - java

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

Related

elasticsearch unable to start - Java exception No such method: java.nio.file.Files.readAllLines(Ljava/nio/file/Path;)

Been trying to upgrade elasticsearch from 2.x to 5.x and while doing this, since straight through upgradation is impossible, a fresh install was necessary. Hence, I downloaded the deb file and tried to install the newer version. I was successful in installing elasticsearch. When I tried to start the server the following exception did raise:
* Starting Elasticsearch Server
Exception in thread "main" java.lang.NoSuchMethodError: java.nio.file.Files.readAllLines(Ljava/nio/file/Path;)Ljava/util/List;
at org.elasticsearch.env.ESFileStore.<init>(ESFileStore.java:65)
at org.elasticsearch.env.Environment.<clinit>(Environment.java:111)
at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:90)
at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:72)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122)
at org.elasticsearch.cli.Command.main(Command.java:88)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84)
[fail]
Java version of my machine is:
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b108)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b50, mixed mode)
I have an openjdk-7-jre running in the machine as well.
Can't find a workaround to this. Any help would be much appreciated.
After three hours of dwelling over resources, I've fixed the issue. There seems to be a version compatibility mismatch across ES 5.x and openjdk-7-jre. I uninstalled the existing openjdk-7-jre and installed openjdk-8-jre, restarted the server again. Elasticsearch is up and running :)

org/hibernate/HibernateException : Unsupported major.minor version 52.0 (unable to load class org.hibernate.HibernateException)

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.

Unsupported major.minor version 51.0 Issue

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 :) )

java.lang.NoSuchFieldError: IBM_JAVA error while running hadoop 2.2.0 in eclipse

Exception in thread "main" java.lang.NoSuchFieldError: IBM_JAVA
at org.apache.hadoop.security.UserGroupInformation.getOSLoginModuleName(UserGroupInformation.java:303)
at org.apache.hadoop.security.UserGroupInformation.<clinit>(UserGroupInformation.java:348)
at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2590)
at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2582)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2448)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:367)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:166)
at org.apache.hadoop.mapred.JobConf.getWorkingDirectory(JobConf.java:653)
at org.apache.hadoop.mapred.FileInputFormat.addInputPath(FileInputFormat.java:408)
at MaxTemperature.main(MaxTemperature.java:25)
I am getting the above error while trying to run a hadoop madp-reduce program in eclipse under Windows-7
JDK Version :
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
same type of question is already asked here :
the IBM_JAVA error for running jobs in Hadoop 2.2.0
but no one has answered.
IBM_JAVA is not a variable used in the code.
I am new to hadoop, i dont know what i am missing. Please help!
The cause is that your java dependancies are not complete, you have lost the jar package hadoop-auth-2.2.0.jar or its newer version
Like user3762708 said, you are missing the hadoop-auth package, add that to your classpath.
Additionally: If the problem persists, remove hadoop-core from your classpath. It will conflict with hadoop-auth.
Add
Hadoop-auth 2.6
Hadoop-core 1.2.1
Hadoop-auth 2.6 --> org.apache.hadoop.util.PlatformName.class has IBM_JAVA (So add the Jar)
org.apache.hadoop.security.UserGroupInformation is present in Hadoop-common and it does not have IBM_JAVA
Then Remove
Hadoop-common x.x if already added

My java applets won't run in browser due to version mismatch although fully updated. How can this be?

Although I can run my applets in "appletviewer", I'm having problems running them in browsers (I'm trying with Firefox and Chrome). I get an error message starting with
"java.lang.UnsupportedClassVersionError: HelloWorld : Unsupported major.minor version 51.0" (the applet is just a rudimentary Hello World-applet by the way).
Reading up on this error, I understand that the problem has to do with a version mismatch. Here is some version info: (all of the below has been updated to the latest version)
java -version
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)
javac -version
javac 1.7.0_03
But http://javatester.org/version.html displays (for both browsers)
"Java Version: 1.6.0_31 from Sun Microsystems Inc."
Am I therefore right to assume that the version of java used by my browsers (downloaded from http://www.java.com/en/download/index.jsp) currently lags behind the JDK AND the JRE that I've downloaded from oracle.com? If so, does that mean that applet developers always have to compile with the "-target" option, to make their applets compatible with the current version of java used by browsers, or is this just a temporary situation?
(I'm using Windows 7)

Categories