Run Ant on Eclipse Mars with Java 1.6

前端 未结 9 1745
梦如初夏
梦如初夏 2020-12-28 16:59

I downloaded the latest release of Eclipse (Mars) and changed the required Java version to 1.6 in eclipse.ini file as my project uses Java 1.6.

I configured installe

相关标签:
9条回答
  • 2020-12-28 17:22

    I faced the same problem after upgrading to Eclipse Mars.

    I solved this by changing the runtime environment of the external tool configuration of the project to JDK7.

    I assume you know how to add JDK7 to your installed jre in eclipse

    Open External Tools Configurations... and then change the JRE to JDK 1.7

    Open External Tools Configurations

    Then change the JRE

    Change JRE

    But this will create another problem, the compiled jar will be in JDK 7 and this will not work on production servers with JDK6.

    To solve this, simply change the target attribute in the task to be 1.6

    <javac target="1.6">

    Change Task target to 1.6

    As per suggested from @dag and @Chris, Here is updated ant javac task. enter image description here

    0 讨论(0)
  • 2020-12-28 17:25

    please take a look at the <javac>reference https://ant.apache.org/manual/Tasks/javac.html#compilervalues and add the following attributes to your <javac>-Task: compiler="javac1.6" source="1.6" target="1.6" executable="[path-to-jdk-1.6/bin/javac]" fork="true" taskname="javac1.6".

    0 讨论(0)
  • 2020-12-28 17:26

    We fixed the problem for us using a patched Ant plugin. For Eclipse Neon, also see this link as is noted in the comments on the first page.

    0 讨论(0)
  • 2020-12-28 17:26

    No you cannot go for JDK1.6 or less because Eclipse Mars only runs with Java >=1.7. Refer this link.

    0 讨论(0)
  • 2020-12-28 17:32

    Solution for me was to download an ant version compatible with JRE 6/7 and change in the "External Tool Configuration" the Ant Home Path to match the one I downloaded (ClassPath > Ant Home")

    0 讨论(0)
  • 2020-12-28 17:34

    I recently ran into this issue with Java 8 being on my machine, using Elicpse Oxygen and trying to use Ant to build a Java 6 project. I used some suggestions above but also encountered some strange behavior during the Ant build process. In the end it worked, here were my steps:

    1) Java home ended up staying pointed to Java 8.

    2) Set in the Ant script the values suggested by @Chris.

    3) Do not change the Ant Runtime JRE, mine was left at 8, and in fact would not run the Ant build if I changed it to 6...

    4) Project settings build path and compiler levels were all set to 6.

    5) Run the build.

    This produces a build at the Java 6 level that worked for me.

    0 讨论(0)
提交回复
热议问题