Error due to version compatibility in running jar file - java

I have created a jar file using JDK 8.0 and I tried to run the jar file in a system which is having JRE 7.0, but I am getting an error like this:
C:\Users\admin\Desktop>java -jar test.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: test : Uns
upported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
What change am I need to make in my jar file creation. So that it will run without version compatibility?

You need to use the -source option for javac. For example:
javac -source 1.7 foo/Bar.java
In theory you can specify the source and target options separately, but judging by your comment, it sounds like you can't use Java 8 language features at all when targeting 1.7.
Note that this only covers your own source code. If xbasej-20091203.jar was built against Java 8, you'll need to find a version which targets Java 7 instead.

Related

ActiveMQ New build, latest version not working with latest Java

I am installing activemq on a new windows 2016 server. I have installed the latest version of Java "1.8.0_321" and the latest download of activemq "5.17.0", but when I try to start activemq I get this error:
Warning: JAVA_HOME environment variable is not set.
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/activemq/console/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
C:\Program Files (x86)\apache-activemq-5.17.0\bin>
The JAVA_HOME variable is set:
Java home variable
When I run
echo %JAVA_HOME%
I get
C:\Program Files (x86)\Java\jre1.8.0_321\bin
From that I would infer that it is correct?
Any ideas please?
It states, on the ActiveMQ home page, that ActiveMQ 5.17.0 release requires JDK 11+.
Your error message indicates the class version number of Java 11, i.e. 55.
Either migrate your code to Java 11 or use ActiveMQ 5.16.4 release which is compatible with Java 8.

Compile with JDK 13 and run with JRE 8

I compiled my program, but when i try to run it, i get this error :
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: Lanceur has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the J ava Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
I tried to "move" the JDK 13 all the way up in PATH, restarted my PC, but nothing changed. Here is a screenshot :
I then tried to download JRE 13, but can't find it anywhere.
How can i do this ?
I can't update to JDK 14 or up, because i need something that was removed in these versions
As you're compiling without a build environment, you'll need to build with:
javac -target 1.8 -source 1.8 MainClass.java
Java versioning is confusing but stick with 13 until you get used to it.

Problem with running my java code in command prompt [duplicate]

This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 3 years ago.
I have java versions 8 and 11 both installed. When I try to run any .java file in cmd using java command, I get the following message:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: aa has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
I've tried installing a newer version of java but nothing has changed.
Java 11 should support file format 55 (https://en.wikipedia.org/wiki/Java_class_file#General_layout). Type java -version on commandline to figure out if you are using the correct installation. If not change your environemnt variables accordingly.

Using Popen() in Python 3.6.2 to open a JAVA class is failing [duplicate]

This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 5 years ago.
This line of code in my Python file seems to return the error:
Could not find or load main class TestClass
TestClass.java is in the same folder as my .py file. Not sure what is going wrong. Any ideas?
process = Popen(['java', 'TestClass'], stdout=PIPE)
Edit: compiling the java file worked, however now i am getting the following error when trying to run it. i tested the java file directly and it worked fine, so it seems to be an issue with python to java versions? i am running java 8 latest build now, and latest build of python...
Exception in thread "main" java.lang.UnsupportedClassVersionError: TestClass : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoa`enter code here`der.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Your python script is looking for a compiled .class file, while you only have the uncompiled .java file.

Java - java.lang.UnsupportedClassVersionError in applet

I wrote not so simple app, and decided to make applet. I have the .jar archive and main class there is chat.java (it contains init() and extends JApplet). I have this code in HTML File:
<applet code="chat.class" archive="chat.jar" width="150" height="150">
Error!
</applet>
And it gives error
java.lang.UnsupportedClassVersionError: chat : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.defineClassHelper(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.access$100(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.UnsupportedClassVersionError: chat : Unsupported major.minor version 51.0
in Java console. I dont know what to do, my applet should open a new Frame (popup) where you can chat and so on.
Thanx for any replies!
You have incompatible version of the class file and the java plugin. For example you compile your code in java7 and trying to run in on java5 or java6.
The Unsupported major.minor version 51.0 means that you have compiled your code in JDK7, and your browser plugin i JRE 6 or older and does not understand it.
In such situation you need to do one of:
update your java plugin (or switch to proper version if you have more), or
compile your applet for the older java using '-target' option.
To check your java version go to plugin test page.
That exception means that you compiled your classes under a specific JDK, but then try to run them under older version of JDK. So, you can't run classes compiled with JDK 6.0 under JDK 5.0. Check your browser JRE version. Also you can specify a target JDK when compiling your classes.

Categories