Search code examples
javaeclipseantjarjava-8

What Apache Ant version should I used to run Java 6 projects?


I have many legacy java 6 projects and I need to build it.

Using Eclipse Neon Ant plugin with Java 8 is building the jar, but when I use the generated jar with another Java 6 project, I have the problem 'Unsupported major.minor version 52.0'.

Do I need to build the jar with an Ant version that runs with Java 6? How do I do that when the latest version of Apache Ant requires Java 1.8+?


Solution

  • It doesn't matter what version of Ant you use or what version of Java it was compiled with.

    What matters is the JDK that the Ant javac task uses and the values of the source and target arguments of the javac task.

    When running Ant from Eclipse you can set the JDK used in the 'JRE' tab of the 'Ant Build' you are using in the 'Run > External Tools Configuration' dialog. Choose a Java 6 JDK.

    Specify source="1.6" target="1.6" on the javac task in your Ant build.xml.