15
votes

I have build.xml file and I want to create Java project from Existing Ant Buildfile. But I have an error: Specified buildfile does not contain a javac task My file has simple structure:

<project>
     <target ...>
     </target>
     ...
</project>
3
And does it have a javac task? What do you expect eclipse to do if your build file doesn't consist in compiling Java source code?JB Nizet
You can specify macros that build all the projects, similar to a parent/module setup with Maven. I am having the same problem; I can build the project from the command line but cannot import into Eclipse.Ryan

3 Answers

10
votes

Provide javac to your build.xml as below:

<javac srcdir="src" destdir="bin" />
3
votes

As Puneet Pandey pointed out, this error occurs when your build.xml file is lacking a <javac> XML element.

The <javac> XML element in the build.xml file (referred to as javac task) tells the compiler or IDE (Eclipse in this case) where the source Java files are for compiling. Once you know that it should be quite clear why Eclipse can't import your build.xml without a <javac> XML element.

In case you are not sure where to stick the <javac> tag I'll add a slightly fuller example. You will need to navigate to your build.xml and edit it so that it contains the <javac> line in the appropriate section inside the <project> tag.

<project ...>
  <javac srcdir="src" destdir="bin" />
  <target ...>
  </target>
  ...
</project>
0
votes

You need something like this,

    <target name="compile">
  <javac destdir="build/classes" srcdir="src" includeantruntime="false">
    <classpath refid="compile.classpath"/>
  </javac>
  </target>

    <target name="war" depends="compile">   
  <war destfile="build/${name}.war" webxml="WebContent/WEB-INF/web.xml">
   <fileset dir="WebContent" casesensitive="no">
   </fileset>
   <lib dir="WebContent/WEB-INF/lib"/>
   <classes dir="build/classes">
   </classes>   
  </war>
</target>