Exception while trying to execute .jar from unix korn shell - java

I'm new using Java and I want to execute a Java program from unix, While I'm trying to execute it I'm getting an the following error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: javaapplicationtest/JavaApplicationTest : Unsupported major.minor version 52.0
I'm using:
java -jar JavaApplicationTest.jar
Do you have any idea how to correct that error?

You seem to have multiple JDK/JRE versions installed on your system.
The code you're trying to run is compiled for JRE 1.8, while the version of java on your PATH is 1.6.
You could do the following things to get your program to run:
Modify your environment variables such that when you try to execute java, it is picking up the 1.8 version. Look up how to do that on the specific UNIX flavor you are running.
If you are compiling the source code yourself, you could change the target runtime to be able to run this code on earlier versions.
javac -target 1.4 JavaApplicationTest.java

Related

Launch4j-FakeMain compiled by more recent version Java Runtime(class file version 55 0)this Java Runtime only recognizes class file version up to 52 0

This is my first application that i try to execute exe.
I'm using launch4j to do this. After executing and trying to run, I get this error:
Blockquote
Launch4j - Exception in thread "main" java.lang.UnsupportedClassVersionError: FakeMain 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
I searched something about versions of java, so I checked my versions of java and they are the same.
That's my versions of java:
My versions of java in cmd
Maybe I did something wrong there?
Screen of Launch4j
I don't know what I can do. I spend all this day about fix this and nothing.
Error after try to run exe file
You have compiled the code with Java 11 as target. But your PC want's to execute the Java Code with Version 8, which is not possible.
Make sure you have installed the correct Versions and also make sure that the executable uses Java 11.
Here you can find the Java Versions mapped to the Runtime Versions: Java Version Numbers
The Article gives you also some information about how to compile and execute for the correct versions.

"A JNI error has occurred, please check your installation and try again" when using terminal

In my past computer science classes, we did all of our work inside Eclipse. Now, I am trying to compile and run java programs using the PowerShell. I am able to compile using javac, but when I try to run the class file with the main method 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: HW has been compiled by a more
recent version of the Java Runtime (class file version 56.0), this
version of the Java Runtime only recognizes class file versions up to
52.0
The program I am trying to run to test this out is just a hello world program.
My versions of Java are Java 8 Update 251(64-bit) and Java SE Development Kit 12.0.2 (64-bit). Are these mismatched in any way or are there any other issues it could be?

Unsupported major.minor version when running a java program from shell script which is executed by a python program [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 a shell script that runs some java program on a remote server.
But this shell script is to be executed by a python script which is on my local machine.
Here's the flow : Python script executes the shell script (with paramiko), the shell script then executes a java class.
I am getting an error : 'The java class could not be loaded. java.lang.UnsupportedClassVersionError: (Unsupported major.minor version 50.0)' whenever I run python code.
Limitations: I cannot make any changes to the shell script.
I believe this is java version issue. But I don't know how to explicitly have a python program to run in a specific java environment.
Please suggest how I can get rid of this error.
The java version of unix machine (where shell script executes) : 1.6.0
Java version of my local machine (where python script executes): 1.7.0
The shell script can stay the same, update java on the remote system to java 1.7 or later. Then it should work.
Another possibility could be to compile the java application for java 1.6 instead. The java compiler (javac) has the arguments -source and -target and adding -source 1.6 -target 1.6 when compiling the application should solve this issue, too (but limits the application to use java 1.6 features).
Also be aware: If you use a build system like gradle or maven, then you have a different way to set source and target version.

Java: I cannot execute a compiled Java code

C:\Users\YusufGalip\Desktop\JavaDeneme>java deneme
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: deneme 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
I got this error when i tried to run a compiled program.
It's probably compiled with a more recent version of java than the one you are attempting to use running the program. Do you have multiple versions of Java installed?
Try java -version and javac -version and compare the versions. If you use and IDE/editor where Java is configured in the settings, see that it points to the expected directory.
You've compiled your class with Java 11 (55) while you're still trying to execute/run them using Java-8(52).
Either compile the code using Java-8 or execute with Java-11.
The error clearly says that the compiler version was higher than the JVM version with which you are trying to run. That is why you are getting the error on running.
Java 8 uses major version 52
Java 11 uses major version 55
Reference:
https://en.wikipedia.org/wiki/Java_class_file#General_layout
=================
#DO THE FOLLOWING
change your path to point to a more recent version or if you are aware of the version using which the program was compiled, install the version and then execute the same command to run
1) run java -version now
2) Note down the version
3) complete the above #DO ****
4) execute 1) again
5) you should see a different or the latest version
6) run your program :) and you should be able to .... post your results
Finally I solved with your help.
There were 2 Java in my computer one of them is "Java SDK Tools 11" and the second one is "Java Runtime 8" I uninstalled the "Java Runtime 8" and it worked.Thank you for your help.

Error: A JNI error has occurred while executing jar file

I'm getting the below exception when i'm trying to run my jar file though powershell using the command java -jar restcall.jar:
Error: A JNI error has occurred, please check your installation and
try again Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/http/client/ClientProtocolException
It complies and runs perfectly in eclipse. Kindly help.
Check the classpath as defined in your Eclipse environment and define the same using the -cp option when invoking java from the powershell.
this error occur because of jdk version and jre version collapse while run time.
if you want to remove the error the check jdk and jre version and if you found the jdk version is different from jre version then uninstall the jdk once and download the jdk version according to version match with your jre setup.now installe it. now try to run a program. you will found it compile and run it successfully.

Categories