Java ClassVersionError although version seems to be okay - java

I'm getting the following error in my java web app (The application launches okay but when I click a button following error occurs). I'm using Tomcat (7.0.109) to run this application.
java.lang.UnsupportedClassVersionError: FileDetailsServlet has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [FileDetailsServlet])
Previously I used Java 15 (class version 59.0). But then I switched to JDK and JRE 1.8.0_311 (class version upto 52.0)because of other 3rd party apps.
Here are some things that I did
I've checked class version of FileDetailsServlet class using this
javap -verbose FileDetailsServlet| findstr "major"
command. And it shows that version is 51.0 (Java 7).
I've set JDK compliance to 1.8 in eclipse. (Project specific settings)
After changing JDK I recompiled all the files using JDK 1.8.0_311
I've checked environment variables. JAVA_HOME is "C:\Program Files\Java\jdk1.8.0_311"
JRE_HOME is "C:\Program Files\Java\jre1.8.0_311" and Path is "C:\Program
Files\Java\jdk1.8.0_311\bin"
Am I missing anything? I can not go back to Java 15. So is there any way around?

Check your class path for any "leftovers" from the old system. It looks like you are not inspecting the correct files. Maybe you have the FileDetailsServlet in a wrong version as depencency somewhere, or just in a "standalone" JAR- or WAR-file.
It is also important that Eclipse settings alone will maybe not cover, how the used container serves the servlet, so which technology do you use to run the FileDetailsServlet? That's the crucial point: this thing that you use to run (Tomcat, Jetty, other container, maybe included in a fat WAR or fat JAR file from Sprint Boot or another similar technology) has to use the correct .class file.
As you are using Tomcat as container:
You should check the class files inside the folder webapps/appname folder below your tomcat folder (replace appname with the deployment context name) Take care: when you run tomcat from Eclipse this could be somewhere completely different than the installation folder on disk, but I don't have an Eclipse installation ready to check that.

Related

Spring Boot Application has been compiled by more recent version of Java runtime

I am trying to launch my jar file for my spring boot application but I keep getting the error that it has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of Java Runtime only recognizes class file versions up to 52.0. I feel like I have tried everything I believe I am using the latest versions of Java. Is there anything I can do? If there is anything to download could you please link it?
Update: I solved the issue by removing the javapath path variable and restarting.
I believe it was the following I removed:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath

why am i getting the noclassdeffounderror after deploying?

I am getting noclassdeffounderror after deploying the jar with changes to a certain class file.
I am able to see the class file in the jar when i extracted the jar file through the 7zip.
I also de-compiled the .class file to find any errors but did not get any thing .
While deploying i Just dragged the .class file from the eclipse work space into a pre existing jar file. does that matter?
Does the jdk version in which the jar file is compiled matter because i am running on jre 1.7 in eclipse but my deployment environment is of jre 1.6 ?
The problem in my mind is that the class added to the jar has been compiled under a different version of Java. I would guess that you've compiled at 1.7 and 12c is running 1.7, whereas 11g is running 1.6. Either compile the class in 1.6 and add it to the jar or recompile the jar in 1.7 and ensure the environment you're running on has 1.7 or above.
A NoClassDefFoundError states that the class was not available during runtime. Make sure you have it in class path or the static initializer (if present) is not breaking. For the later, you will see an ExceptionInInitializerError somewhere below in the stacktrace.
Not too sure about if jdk version matters or not.
I am getting noclassdeffounderror after deploying the jar with changes
to a certain class file.
This is caused when there is a class file that your code depends on, and it is present at compile time but not found at runtime (see this answer).
While deploying i Just dragged the .class file from the eclipse work
space into a pre existing jar file. does that matter?
Yes, it matters. Be sure to put the class file back in the correct package folder. For example, a class in package com.foo must be in the folder com/foo inside the jar file. It's possible your altered version landed somewhere else when you dragged it into the jar file.
Does the jdk version in which the jar file is compiled matter because
i am running on jre 1.7 in eclipse but my deployment environment is of
jre 1.6 ?
The jar file itself is just a zip file, so no, it doesn't matter which version of Java you were using to compress the contents of the jar file.
However, if you've re-compiled a single class from an existing jar file, it does matter which version of Java was used to compile the other classes in the jar file, because you could cause the class to be incompatible with its companion classes.
This worked perfectly when i compiled the code in jdk 1.6 . java.security.SecureClassLoader is changed in both the versions. thats why i suppose i got the error .

E(fx)clipce with Inno Setup wrong jre folder name

I am following JavaFX tutorial found at
http://code.makery.ch/java/javafx-8-tutorial-part7/
which describes how to create native installer with 'Inno Setup'.
I am using e(fx)clipse 4.4 with java 8 JRE installed only and 1.8 compiler
and i do it for windows (exe).
Everything works fine, but when i install exported native application it create folders for JRE
runtime/jre8/
program wont start and says
jvm.dll is not found in bundled runtime.
if i change manualy runtime/jre8/ to runtime/jre/ - it start without any problem.
I did not found any settings in project for specifing runtime path.
How do i make my native installer make right path for runtime?
Solved. Just noticed that i was using standalone jre for project c:\dev\java\jre8 but supposed to use jre from jdk package c:\dev\java\jdk1.8.0_05\jre.
Now installer creates proper path for runtime - runtime/jre/

JAR file does not load class files from ext

I installed JDK 1.6 on my Linux system, the $JAVA _HOME directory is /usr/java/jdk1.6.0_07.
I built the path on Eclipse to $JAVA_HOME. It runs smoothly through Eclipse and loads all third party JAR files from /usr/java/jdk1.6.0_07/jre/lib/ext/, but when I export the JAR file and run it, it throws ClassNotFoundExecption.
Why?
Did you install Java properly? Here are some instruction for installing Java 7 or Java 6
Are you sure that the version of Java you are using is correct one since there can be several versions of java on linux? Try java -version on terminal where you run it to check.
Do you use any third party library? If so, did you specify the class path when you run the jar file or bundle them inside your jar file?
What does java -version return? Are you using the same JRE for execution?

How to compile .war for Java 5/Tomcat 5.5 in Ubuntu?

I try to compile a webtools project for Java5/Tomcat 5.5 in ubuntu (with manually installed eclipse 3.4). I set the installed jre to java-1.5.0-sun-1.5.0.18 and the compiler compliance level to 1.5. When I export this to a .war file, and try to deploy it in Tomcat (Windows XP, Tomcat 5.5.27, Java 1.5.0_18) , I get the following error:
SEVERE: Error deploying web application archive Jdbc2Ei.war
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
...
Anybody knows how to solve this?
java.lang.UnsupportedClassVersionError: Bad version number in .class file
check that all your jars are compiled for java5.
Compiled it under windows, and it works! Some bug somewhere... there will be a time that this problem will be fixed.
If it works in Windows, it's probably due to a difference in environments rather than a bug present in the Linux versions of the JDKs. Check to see if you have multiple JVMs present in Linux (you almost certainly do, since Ubuntu probably comes with a non-Sun version) and be 110% sure that you're using the expected version to compile. Issuing
which javac
and
echo $JAVA_HOME; echo $JDK_HOME
from a command-line might help too, since all of these could feasibly be used to locate a JDK (as well as the settings you use in your compile command/tool).
Your tomcat is running a lesser JDK than the one used to compile some of your classes. Recompile with a compatible JDK or upgrade the JRE for the tomcat.
A naive one:
After changing project preferences and before exporting the WAR file on Ubuntu, did you try to force compile on your projects ( Project -> Clean... in Eclipse) ?

Categories