0

I have a large project which is build using Java 1.6 and I can not update its build path to Java 1.8 because it causes too many compile errors.

I have to use an external library (underscore) https://mvnrepository.com/artifact/com.github.javadev/underscore/1.73 which is build using Java 1.8 and it seems it is not backwards compatible.

When I try to compile I get the following error for a sample code:

import com.github.underscore.lodash.U;

public static void main(String args[]) {
    U.xmlToJson("foo")
}

I get the following errors:

cannot access com.github.underscore.lodash.U bad class file has wrong version 52.0, should be 50.0. Please remove or make sure it appears in the correct subdirectory of the classpath.

The runtime can be 1.6 or 1.8 it is not problem, the main problem is the compile process fails.

benchpresser
  • 2,171
  • 2
  • 23
  • 41
  • 3
    You need to use at least Java 8 to compile your entire project, otherwise it will not be able to recognize class files compiled with Java 8. That said: Java 6 is 16 years old and unsupported, and Java 8 is 8 years old at this point, with minimal support. Consider switching to Java 17 (LTS) or 18, or failing that, 11 (also LTS). – Jeroen Steenbeeke Aug 29 '22 at 08:10
  • yes, it seems the only way. but I am confused: I got this error when compile using javac or ant scripts. But on eclipse, I generated a dummy project which has jdk 1.6.45 as jre system library in the build path and project compilance is 1.6. I add the external jar (unerscore) and write a simple call as stated in the question above and it compiles fine? – benchpresser Aug 29 '22 at 08:36
  • Eclipse has its own compiler called `ecj`, perhaps it's a higher Java version than your JRE? – Jeroen Steenbeeke Aug 29 '22 at 08:37
  • prject properties/java build path/has two entires: the underscore and JRE Sysem library 1.6.45 which is set as alternate JRE. Maybe eclipse ecj can handle it different than javac even if it is using 1.6? – benchpresser Aug 29 '22 at 08:39
  • Right-click your project, go to Properties, and check under Java Compiler (not Build Path). I'm guessing your compliance level is set higher than Java 6 – Jeroen Steenbeeke Aug 29 '22 at 08:51
  • no compiler compilance level is set to 1.6 explicitily. that is why i get confused. and the classes are generated? Maybe eclipse adds a parameter while compiling etc, which resolves the issue? I also added some java 1.7 or 1.8 feature to my simple main function to check whether it is really 1.6 specific and it does not get compiled. – benchpresser Aug 29 '22 at 09:10
  • 1
    To be fair I rarely use Eclipse (IntelliJ user), so if the compliance level is not set to a higher version then I'm out of ideas why this works in Eclipse. Either way upgrading your project should solve it for all compilers – Jeroen Steenbeeke Aug 29 '22 at 09:14

0 Answers0