ant Unsupported major.minor version 52.0 - ant

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

Related

Java code is 1.8 supported, SonarQube version supports Java 11, the build fails in Jenkins

folks!
I have 2 separate servers on Linux for Jenkins and Sonarqube. The code is written in Java 1.8 and can be compiled using Jenkins. Everything works fine.
It fails at the SonarQube step because our SonarQube uses Java 11, and it fails with this error.
ERROR: Error during SonarScanner execution java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation 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
How can I fix this?
You have to run the sonar scanner with at least Java 11, no matter what version of Java your application supports.
Two years ago I had a similar issue. I don't know if your app and sonarqube should run on the same machine (as it was in my case).
If yes, just install both versions of java and set the path of Java 11 to SonarQube settings.
According to sonarqube community, you should do the following:
Edit conf\wrapper.conf, specifically the wrapper.java.command to following:
wrapper.java.command=C:\Program Files\Java\open jdk-11.0.2\bin\java
#wrapper.java.command=java

Javac throwing unsupported error while Eclipse works fine

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.

Ant sonar command not works

I am trying to insert sonarqube setup on build.xml, getting unsupported error.
My build Java version support 1.6
Ant.sonar.qube support 2.5
If I use have version 1.8 my ant sonar command is working.ant command is not working.if I use java 1.6 ant is working and ant sonar is not working.
You already know exactly what your problem is:
If I use have version 1.8 my ant sonar command is working
...
if I use java 1.6 ant is working and ant sonar is not working.
You're facing incompatibility with the version of Java you're trying to use. Since analysis will not work with 1.6, you're best off upgrading to Java 8 and working to make whatever your other Ant target is work with that.

apache ant runs properly but ask me for some other things also

When I use Apache-Ant following :
ant -version
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.0_111\lib\tools.jar
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
However, it works properly but why it shows this and how can I resolve this?
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.0_111\lib\tools.jar
It is because, you have installed JRE while it is required to install JDK.
Please refer System Requirements of Ant
For the current version of Ant, you will also need a JDK installed on your system, version 1.4 or later required, 1.7 or later strongly recommended. The more up-to-date the version of Java , the more Ant tasks you get.
Note: If a JDK is not present, only the JRE runtime, then many tasks will not work.
So, install JDK and
set JAVA_HOME correctly
add %JAVA_HOME%\bin to PATH

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