Javac throwing unsupported error while Eclipse works fine - javac

I tried to use cmd prompt to execute my java file but I got this error that says
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: MovingObject has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java Runtime only recognizes class file versions up to 52.0
but when I tried executing my java file on eclipse it works perfectly fine, its just that I want to try and run it to the command prompt to see if both ways works. Tried searching about the problem but most of the other problems is way back from long ago.

The problem was that my computer was confused as to what JRE to use. I have manually installed JDK and JRE 8 before.
So when I tried checking it through cmd.
javac -version is Java 16
while, java -version is Java 8
So, I uninstalled my Java 8 since I have installed JDK 16 and JRE version 16 on my eclipse which confuses my computer as to what version to use. That's pretty much it.

Related

"main has been compiled by a more recent version of the Java Runtime", Unsure of what the issue is

I was trying to compile and run a java file using command prompt, first used "javac main.java" then ran the class file with "java main"
Upon running the class file, I'm hit with an error:
"Error: A JNI error has occurred, please check your installation and
try again Exception in thread "main"
java.lang.UnsupportedClassVersionError: main has been compiled by a
more recent version of the Java Runtime (class file version 61.0),
this version of the Java Runtime only recognizes class file versions
up to 52.0"
I then found this possible solution, and updated my User Variables "Path" to jdk17.0.1\bin, and my System Variables "Path" to jre1.8.0_311\bin. I was a bit confused on which Path I was to updated/change so I just updated both...? Not sure if this was the correct thing to do.
In addition, both java -version and javac -version output the latest version "17.0.1" and "jre1.8.0_311".
java -version and javac -version :
Error Message :
What confuses me is that running code in eclipse works fine, so I'm not quite sure that it's an issue with Path so I'm not sure what the issue is.

Javac doesn't exist [duplicate]

This question already has answers here:
javac cannot be run, and furthermore does not seem installed
(4 answers)
Closed 4 years ago.
Well i tried to start with react native when suddenly i got an error that java compiler couldn't be found. So i searched and find something about java_home which i fixed but still the compiler isnt found. After testing in the cmd prompt javac -version couldn't it recognise any javac. Then i looked in the bin folder in java jre and realised that the javac doesnt even exist. Is this some kind of bug or should i reinstall it or something.
enter image description here
The image shows a JRE. javac is java compiler, if it's required you need to install JDK.
Try installing jdk as jre is for executing already compiled code. But for a whole new compilation you require a jdk that is development tools of java development toolkit. As javac.exe is a part of jdk not jre.

ant Unsupported major.minor version 52.0

This is driving me nuts.
When running any ant command (even ant -version), I always get the following error on Mac OSX:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/tools/ant/launch/Launcher : Unsupported major.minor version 52.0
I removed and re-installed ant entirely, and still get the same error.
For our company we have to run Java7 to run the command, so I created an alias.
This used to work, I'm not sure what changed.
I see you have java 1.7 installed and post that you have installed Ant 1.10.
Ant 1.10 requires jdk 8
Refer : http://ant.apache.org/
The Apache Ant team currently maintains two lines of development. The
1.9.x releases require Java5 at runtime and 1.10.x requires Java8 at runtime. Both lines are based off of Ant 1.9.7 and the 1.9.x releases
are mostly bug fix releases while additional new features are
developed for 1.10.x. We recommend using 1.10.x unless you are
required to use versions of Java prior to Java8 during the build
process.
Try using Ant 1.9.x if you can't use java 8
Here is a list of minimum java version for given ant version

unable to locate the java compiler com.sun.tools.javac.Main, please change your classloader settings

The following error is occurring while compiling my grails application. I'm using jdk-7u79-windows-x64, I already added the location 'C:\Program Files\Java\jdk1.7.0_79\bin' to my path in Environment Variables. But still the probem exist. My OS is windows 10 (64 bit) and I'm using ggts-3.6.4 (64 bit)
Could anyone tell me why this is happening?
.Error
|
Compilation error: startup failed:
General error during semantic analysis: unable to locate the java compiler com.sun.tools.javac.Main, please change your classloader settings
java.lang.ClassNotFoundException: unable to locate the java compiler com.sun.tools.javac.Main, please change your classloader settings
at org.codehaus.groovy.tools.javac.JavacJavaCompiler.findJavac(JavacJavaCompiler.java:190)
at org.codehaus.groovy.tools.javac.JavacJavaCompiler.compile(JavacJavaCompiler.java:49)
at org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit.gotoPhase(JavaAwareCompilationUnit.java:102)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:548)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:517)
at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:59)
at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:215)
at org.codehaus.groovy.ant.Groovyc.runCompiler(Groovyc.java:1161)
at org.codehaus.groovy.ant.Groovyc.compile(Groovyc.java:1212)
The Groovy-Grails Tool Suite is no longer supported software. I recommend using IntelliJ IDEA instead. See my answer to this question for more details: https://stackoverflow.com/a/38938933/2970843.
First make sure that you have set the path correctly(I had some problems with that).
Also use the java -version command in cmd to see if you are using the same jdk you've set or not
I had set the JAVA_HOME correctly but I had 2 other versions of jdk and the newest was shown as java version,so I deleted them and my problem was solved,hope this workes for you

Execution of Java program

After searching all over the web, I am not able to solve my problem of Java execution. When using command prompt to run my "first" Java program, I am faced with the errors of Unsupported class version and Main class not found. Program will exit.
I have 2 versions of Java on my PC, Java 6 and 7. I have set the path of the JDK 7 in path environment variables and classpath too. I know the problem: I have javac -version as 1.7.02 and java version as 1.6.02, but how to change it and fix the problem?
Please elaborate the problem in easy and understandable language!
You have to run your program with the same or higher version of java that yxou compiled it with.
So you can either compile your program with Java 6 on your PC or run it with java 7.
To run your program with java 7 just use the complete path to your java runtime environment. for instance
c:\jdk7\bin\jawaw.exe yourprogram
How to tell your system which Java version to use is explained here:
Why does java -version returns old version?
JRE [java command] come with your JDK 1.7, and you must change your JAVA_HOME variable to your JDK 1.7 folder.for this work read this article

Resources