Personal tools
User menu

Knowledge Base/Tools/Ant

From Thalesians

Jump to: navigation, search

A sample Ant script

<?xml version="1.0"?>
<project name="MyProject" default="compile">
	<target name="clean" description="Remove intermediate files">
		<delete dir="classes"/>
	</target>
	<target name="compile" description="Compile the source code">
		<mkdir dir="classes"/>
		<javac srcdir="src" destdir="classes"/>
	</target>
	<target name="jar" description="Create a Jar file for the project">
		<fileset dir="classes" includes="**/*.class"/>
		<manifest>
			<attribute name="Main-Class" value="HelloWorld"/>
		</manifest>
	</target>
</project>

"Unable to find a javac compiler" on using Ant Build in Eclipse

Go to Window > Preferences... then drill down to Ant > Runtime in the Preferences dialog box. Go to the Classpath tab. Select "Global Entries" and click on "Add External JARs...". Browse to <JDK directory>/lib/tools.jar. tools.jar will now appear under "Global Entries". Click "OK". The problem should now be resolved.

javac tasks fail

If you see messages like the following

BUILD FAILED
build.xml:80: The following error occurred while executing this line:
build.xml:85: The following error occurred while executing this line:
build.xml:102: Error running javac.exe compiler

it may be difficult to figure out what's going on at first (it's "Error running javac.exe compiler", but why?).

To get more clarity, you may wish to run Ant with the -debug -verbose flags. You may see a FileNotFoundException, i.e. Ant doesn't know where javac.exe is.

On Windows this can be fixed by adding javac.exe to the system PATH (via Control Panel / System / Advanced).

  • This page was last modified on 6 November 2008, at 14:51.
  • This page has been accessed 6,715 times.