Question

I am trying to build a project using Ant in eclipse. I right-clicked on build.xml > Run As > Ant Build. However, I am getting the following error:

BUILD FAILED
C:\Users\David\eclipse\test-project\build.xml:26: Class not found: javac1.8

and also a warning:

compile:
[javac] C:\Users\David\eclipse\test-project\build.xml:26: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

As I read in other posts that this might be due to having an ant version that is too old or not having set the environment variables correctly here is all the info:

C:\>java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

C:\>ant -version
Apache Ant(TM) version 1.9.3 compiled on December 23 2013

C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.8.0_05

C:\>echo %JRE_HOME%
C:\Program Files\Java\jre8

EDIT: Here is the whole build.xml, line 26 is the javac tag:

<?xml version="1.0"?>
<project name="test-project" default="main" basedir=".">
  <!-- Sets variables which can later be used. -->
  <!-- The value of a property is accessed via ${} -->
  <property name="src.dir" location="src" />
  <property name="build.dir" location="bin" />
  <property name="dist.dir" location="dist" />
  <property name="docs.dir" location="docs" />

  <!-- Deletes the existing build, docs and dist directory-->
  <target name="clean">
    <delete dir="${build.dir}" />
    <delete dir="${docs.dir}" />
    <delete dir="${dist.dir}" />
  </target>

  <!-- Creates the  build, docs and dist directory-->
  <target name="makedir">
    <mkdir dir="${build.dir}" />
    <mkdir dir="${docs.dir}" />
    <mkdir dir="${dist.dir}" />
  </target>

  <!-- Compiles the java code (including the usage of library for JUnit -->
  <target name="compile" depends="clean, makedir">
    <javac srcdir="${src.dir}" destdir="${build.dir}">
    </javac>
  </target>

  <!-- Creates Javadoc -->
  <target name="docs" depends="compile">
    <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
      <!-- Define which files / directory should get included, we include all -->
       <fileset dir="${src.dir}">
                <include name="**" />
           </fileset>
    </javadoc>
  </target>

  <!--Creates the deployable jar file  -->
  <target name="jar" depends="compile">
    <jar destfile="${dist.dir}\test-project1.jar" basedir="${build.dir}">
      <manifest>
        <attribute name="Main-Class" value="test.Main" />
      </manifest>
    </jar>
  </target>

  <target name="main" depends="compile, jar, docs">
    <description>Main target</description>
  </target>

</project> 
Was it helpful?

Solution

The version of Ant bundled with your version of Eclipse is not compatible with Java 1.8.

Go to the Ant download page, and extract the latest version somewhere appropriate onto your filesystem.

In Eclipse, go to Window > Preferences > Ant > Runtime, click the Ant Home... button, and select the location that you extracted the newly downloaded Ant to.

OTHER TIPS

To make it still more clear.

1>Set JAVA_HOME,JRE_HOME and Update Ant to 1.9

2>Over build.xml right click => run as (this takes into configuration)==>Now in this Edit Configuration and launch pop-up window

select Main tab then the third form field called "Arguments" add:

-Dbuild.compiler=javac1.7

3> In build.xml add includeantruntime="false"

<javac srcdir="${src}" destdir="${bin}" debug="true" encoding="ISO-8859-1" includeantruntime="false">
        <classpath refid="my.classpath"/>
</javac>

Edit configuration

It should compile without any message

Mr. studro is right. I just confirmed an example on Ubuntu 14.04

sudo apt-get install ant
ant -version
Apache Ant (TM) Version 1.9.3 compiled on April August 2014

works perfectly in eclipse, just follow the steps described by Mr studro to configure the 'Ant Home' in eclipse with "/usr/share/ant".
Regards, Stéphane.

I think, what you are seeing is Ant Bug 53347 (see https://issues.apache.org/bugzilla/show_bug.cgi?id=53347).

If so, try either pf the following workarounds:

Set the property "build.compiler" to a meaningful value like "javac1.7", or "javac1.3".

Set the "compiler" attribute of the "javac" element of your build script to either of the above values. For all possible values, and their meaning, see http://ant.apache.org/manual/Tasks/javac.html

Make sure your source files are in "ProjectDirectory/src".

I already did some extensive googling before asking this question but continuing that I found a solution here: This issue seems to only appear when using JDK 1.8 so using JDK 1.7 instead solves the problem. The following line needs to be added to eclipse.ini:

-vm "path-to-jdk-1.7\bin\javaw.exe"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top