0

I am running Eclipse Luna Service Release 2 (4.4.2). For a java project I am not able to degrade major version from 52(java 8) to 50(java 6) for class inside runnable jar file. When I run java program inside my eclipse it is running but when I create jar file it is showing error Unsupported major.minor version 52.0. I don't have java 7 and java 8 installed on my system.

1 Answers1

0

Not able to change the major (class file) version of a runnable jar file in Eclipse.

Correct. You cannot do that.

The version number is not the JAR file's version number. It is the version number of the class file format that is used to represent the classes in that JAR. (And technically speaking, different class files in a JAR could have different class file version numbers.)

What you actually need is to recompile the code from source code specifying a different compiler version number. This can be done in Eclipse using the project settings, or (with Maven) in the POM file(s). But note that you will get best results if Eclipse has access to a JDK / JRE for the target Java version.

(I haven't checked if the Eclipse Luna compiler is still capable of generation code for Java 6. I vaguely recall that this option is being dropped for some Java compilers. Supporting code generation for multiple old platforms gets in the way of progress. So you might have to use an older version of Eclipse ...)


Having said of this, you should not be using Java 7 or earlier. They have been end-of-life for a number of years. You are missing years of security patches and other good stuff. It is advisable to upgrade your build and execution platforms to at least Java 8 or Java 11 ... as soon as practical.

I don't have java 1.7 and 1.8 installed on my system.

Yea ... fix that. Install Java 1.8 == Java 8.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks but I recompiled the code and export runnable jar file again but still the result is same. Actually i need java 6 compiled class only. I don't have java 7 and java 8 installed in my system then how java class files are being compiled of version 52. – Satish Dalal Jan 23 '20 at 08:18
  • Eclipse uses an internal compiler; see "[how do I get eclipse to use a different compiler version for Java?](https://stackoverflow.com/questions/2540548/how-do-i-get-eclipse-to-use-a-different-compiler-version-for-java)". – Emmanuel Chebbi Jan 23 '20 at 08:40
  • Correct. And that compiler is capable of generating bytecodes for a number of "target" classfile versions. So, you need to configure Eclipse to do what you want; see my Answer. Alternatively run your compilations from the command line using a build tool like maven, ant, gradle, and set the build instructions appropriately. – Stephen C Jan 23 '20 at 09:26