Ant build file

From Just Solve the File Format Problem
Jump to: navigation, search
File Format
Name Ant build file
Ontology
Extension(s) .xml

Ant build file is a file named build.xml which resides in the root directory of Java or Scala projects and allows building and testing of the project without the need to compile each file separately by hand. It is an XML based file format.

Example

<?xml version='1.0'?>

<project name='infocomp' default='dist' basedir='.'>
	<description>
		Information Compiler for Anonymous XML Standard
	</description>

	<!-- set global properties for this build -->
	<property name='src'   location='src'/>
	<property name='build' location='build'/>
	<property name='dist'	 location='dist'/>
	<property name='lib'	 location='lib'/>
	<property name='javadoc' location='javadoc'/>
	<property name='data'	 location='dat'/>
	<property name='test'	location='test.src'/>
	<property name='build-test'	location='test.build'/>
	<property name='junit.location'	location='/usr/share/java/junit4.jar'/>
	<property name='distfile' value='${dist}/fms2frost.jar'/>

	<property name='source-version' value='1.6'/>

	<property name='jaxb.home' value='/usr/lib/jvm/jaxb'/>

	<path id='classpath'>
		<fileset dir='${jaxb.home}' includes='lib/*.jar'/>
		<fileset dir='${lib}' includes='*.jar'/>
	</path>

	<!-- for the use of JAXB -->
	<taskdef name='xjc' classname='com.sun.tools.xjc.XJCTask'>
		<classpath refid='classpath'/>
	</taskdef>

	<!-- making directories -->
	<target name='mkdir'
	  description='Prepare directories for server'>
		<echo message='Creating needed directories...'/>
		<mkdir dir='${build}'/>
		<mkdir dir='${dist}'/>
		<mkdir dir='${build-test}'/>
		<mkdir dir='${src}/net/anonymity/freenet/frost/message'/>
	</target>

	<target name='env' depends='mkdir'
	  description='Learn about the environment of the build machine'>
		<available file='${junit.location}' property='junit.present'/>
	</target>

	<target name='compile' depends='generate'
  	  description='Compile'>
		<!-- compiling the source -->
  		<echo message='Compiling the source...'/>
		<javac srcdir='${src}' destdir='${build}' debug='on' optimize='on' nowarn='false' source='${source-version}' target='${source-version}'>
			<classpath refid="classpath"/>

			<!-- following a very temporary list of files to be build -->
			<include name='**/*.java'/>
			<exclude name='**/*Test.java'/>
		</javac>
	</target>

	<target name='generate' depends='mkdir'
		description='Generate all the autogenerated code'>
		<!-- Create the time stamp -->
		<tstamp/>

  		<!-- generate the Java content classes from the schema -->
		<echo message='Compiling the schema...'/>
		<xjc schema='${data}/frostMessage.xsd' destdir='${src}' package='net.anonymity.freenet.frost.message'
			extension='true'
			removeOldOutput='yes'>
			<produces dir="${src}/net/anonymity/freenet/frost/message" includes="*.java"/>
		</xjc>

		<echo message='Copying xsd files...'/>
		<copy todir="${build}/net/anonymity/freenet/frost" overwrite="true">
			<fileset dir="${data}"/>
		</copy>
	</target>

	<target name='dist' depends='compile,unit'
	  description='Generate the distribution' >
		<jar jarfile='${distfile}' basedir='${build}'>
			<manifest>

				<attribute name='Main-Class' value='net.anonymity.freenet.fms2frost.FMS2Frost'/>
				<attribute name='Built-By' value='${user.name}'/>
				<section name='common'>
					<attribute name='Specification-Title' value='freekiwiki'/>
					<attribute name='Specification-Version' value='${product-version}'/>
					<attribute name='Specification-Vendor' value='freekiwiki.sf.net'/>
					<attribute name='Implementation-Title' value='freekiwiki'/>
					<attribute name='Implementation-Version' value='${product-version} ${TODAY}'/>
					<attribute name='Implementation-Vendor' value='freekiwiki.sf.net'/>

				</section>
			</manifest>
		</jar>
	</target>

	<target name='run'
	  description='Run the distribution' >
		<echo>Not yet implemented</echo>
	</target>

	<!-- ================================================== -->
	<target name='clean'
	   description='Delete class files and docs dir.'>
  		<echo message='Removing old build and distribution...'/>
		<delete dir='${build}'/>
		<delete dir='${build-test}'/>
		<delete dir='${dist}'/>

		<echo message='Removing old JAXB implementations...'/>
		<delete dir="${src}/net/anonymity/freenet/frost/message"/>
	</target>

	<target name='unit-build' depends='compile,env' if='junit.present'
	  description='Build the JUnit files'>
		<echo message='Building the JUnit tests'/>
		<javac srcdir='${test}' destdir='${build-test}' debug='on' optimize='on' source='1.6'>
			<classpath>
				<pathelement path='${build}'/>
				<pathelement location='${junit.location}'/>
			</classpath>
			<include name='**/*.java'/>
		</javac>
	</target>

	<target name='unit' depends='unit-build,env' if='junit.present'
	  description='Run the JUnit tests'>
		<echo message='Running JUnit test'/>
		<junit printsummary='yes' fork='yes' haltonfailure='yes'>
			<classpath>
				<pathelement path='${build}'/>
				<pathelement path='${build-test}'/>
				<pathelement location='${junit.location}'/>
			</classpath>

			<formatter type='plain' usefile='false'/>

			<batchtest fork='yes'>
				<fileset dir='${build-test}'>
					<include name='**/*Test.class'/>
				</fileset>
			</batchtest>
		</junit>
	</target>

	<target name='javadoc' depends='mkdir'>
		<javadoc sourcepath='${src}' destdir='${javadoc}'>
			<fileset dir='${src}' includes='**/*.java' />
		</javadoc>
	</target>
</project>
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox