Skip to main content

Source code file content

Revision: 596ec991c20ca0a6448cd2fc400d14ad9d4a5195

Adding simple build.xml
» Project Revision History

» Checkout URL

ant-super-simple-code / build.xml

Size: 3930 bytes, 1 line
<!-- 
Ant simple sample project.
 Kick start your java builds.
 Find out more at http://www.bodkinconsulting.com
 or http://java.net/projects/ant-simple-sample 
 
Instructions:
Put this file in an empty directory and run the 'ant' command in that directory. The build file will create directories and make a very empty jar file in the same directory as the build.xml.

Create src/HW.java and put this code in it.

public class HW
{
    public static void main(String [] args)
    {
        System.out.println("Hello World");
    }

}

in the build file below change  
<property name="main_class_name" value="changeme"/> 
to 
<property name="main_class_name" value="HW"/>
 
Run the ant command again, and now you can run your main class with the command
java -jar antsimple.jar

It should print:
Hellow World
and exit.

Add a junit.jar (from junit.org) into your ANT_HOME/lib directory and run 'ant test'
 
Create the file test/HWTest.java and add this code.
import junit.framework.*;
public class HWTest extends TestCase {
    public void testTrue()
    {
        assertTrue(true);
    }
}

 -->

<project name="antsimple" default="dist" basedir=".">
    <description>
        Ant Simple Sample File
    </description>
  <!-- set global properties for this build -->
  <property name="ant.project.name" value="antsimple"/>
  <property name="main_class_name" value="changeme"/>
  <property name="jarname"  value="${ant.project.name}"/> 
  <!-- set directories -->
  <property name="src" location="src"/>
  <property name="test" location="test"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>
  <property name="lib"  location="lib"/>

  <path id="project.classpath">
    <pathelement location="${build}" />
    <pathelement location="${lib}" />
  </path>


  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create directories if needed -->
    <mkdir dir="${src}"/>
    <mkdir dir="${test}"/>
    <mkdir dir="${build}"/>
    <mkdir dir="${dist}"/>
  </target>

  <target name="compile" depends="init" description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac debug="true" 
	   srcdir="${src}" 
	   destdir="${build}"
	   classpathref="project.classpath"/>
    <!-- Copy files from ${src} into ${build} -->
    <copy todir="${build}"> 
        <fileset dir="${src}">
          <exclude name="**/*.java"/>
        </fileset>
    </copy>
  </target>

<!-- 
Broken??? 
-->
  <target name="test" depends="compiletest" description="run the tests " >
    <junit printsummary="yes" fork="yes" haltonfailure="yes">
      <formatter type="plain"/>
      <batchtest fork="true">
        <fileset dir="${test}">
          <include name="**/*Test*.java"/>
        </fileset>
      </batchtest>
      <classpath refid="${project.classpath}" />
    </junit>
  </target>

  <target name="compiletest" depends="compile"
        description="compile the tests " >
        <javac debug="true" 
               srcdir="${test}" 
               destdir="${build}"
               classpathref="project.classpath" />
  </target>

  <target name="dist" depends="compile" description="generate the distribution" >
    <!-- Create the distribution directory -->

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/${jarname}-${DSTAMP}.jar" basedir="${build}">
        <manifest>
        <attribute name="Main-Class"
                value="${main_class_name}"/>
        </manifest>
    </jar>
    <copy file="${dist}/${jarname}-${DSTAMP}.jar" tofile="./${jarname}.jar" overwrite="true"/>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} directory-->
    <delete dir="${build}"/>
  </target>
</project>

 
 
Close
loading
Please Confirm
Close