Today, faced with this problem, I also browsed the Internet and could not find a direct answer. In my case, using a higher version of Java was not possible, because the project had to be deployed in JDK 6. However, in the end I found a solution, hope this helps someone else.
The key moment Java is compatible with feedback .
This is the answer:). You can use a higher version of the JDK , such as 1.7 or 1.8 , to compile your project and use the -target option to cross-compile to a lower version.
-target version
Generate class files for the specified version of the virtual machine. Class files will run on the specified target and in later versions, but not on earlier versions of the virtual machine. Acceptable goals: 1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6) and 1.7 (also 7).
The default value for -target depends on the value of -source:
If -source is not specified, the value of -target is 1.7
If -source is 1.2, then -target is 1.4
If -source is 1.3, then -target is 1.4
If -source is 1.5, then -target is 1.7
If -source is 1.6, then -target is 1.7
For all other -source values, the -target value is the -source value.
Link: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html
I used Maven, so I just had to change the <java.version> property in the POM , and thatβs it. I still used Java 8, with the latest Maven, but maven cross-compiled JDK6.