Home  |  Contact         

Zrinity is the leader in enterprise-class email marketing management solutions and content management solutions for marketing professionals and developers worldwide.
Products Services Solutions Support Resources Partners Company
Java, PHP, CF Code Samples

A simple example build.xml file with tasks for compiling, running and jaring a java file

Put build.xml in a directory, then create the following directory tree:

/
 - /src/
 - - /com/
 - - - /cfdev/
 - - - - /hello/
 - - - - - HelloWorld.java
 - /include/
 - - anyjarToAddToClassPath.jar
 - build.xml

then run the ant task, after installing Jakarta Ant.

> ant
    this will run the default task called "run" which invokes the dependent tasks jar, compile, and init

if you just want to compile the classes run

> ant compile

if you want java docs:

> ant docs


build.xml:
<?xml version='1.0'?>
<project name="HelloAnt" default="run" basedir=".">

  <!-- set global properties for this build -->
 
  <property name="version" value="8.3"/>
 
  <property name="src" value="src"/>
  <property name="build" value="build"/>
  <property name="lib"  value="lib"/>
  <property name="classpath"  value="classes"/>
  <property name="jarname" value="hello.jar"/>
  <property name="docs" value="docs"/>
  <property name="include" value="include"/>
  <property name="runclass" value="com.cfdev.hello.HelloWorld"/>
 
 

  <target name="init">
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}" />
 <!-- Create the directory for the jar file -->
    <mkdir dir="${lib}" />
 <!-- Create the directory for the java docs -->
    <mkdir dir="${docs}" />
  </target>

  <target name="compile" depends="init">
   <!-- copy all .java files from ${src} to ${build}  -->
    <copy todir="${build}/">
      <fileset dir="${src}" includes="**/*.java"/>
   <!-- apply a substitution @version@ with the value of ${version} -->
      <filterset>
   <filter token="version" value="${version}"/>
      </filterset>
    </copy>
 <!-- run javac to compile the source files -->
    <javac srcdir="${build}" destdir="${build}">
  <classpath>
    <!-- use the value of the ${classpath} property in the classpath -->
       <pathelement path="${classpath}"/>
    <!-- include all jar files  -->
       <fileset dir="${include}">
           <include name="**/*.jar"/>
       </fileset>
  </classpath>
 </javac>
 
  </target>

  <target name="jar" depends="compile">
    <!-- make a jar file -->
    <jar jarfile="${lib}/${jarname}" basedir="${build}/"/>
  </target>
 
  <target name="docs" depends="compile">
   <!-- create javadocs -->
 <javadoc packagenames="com.cfdev.hello.*"
           sourcepath="${build}"
           defaultexcludes="yes"
           destdir="${docs}"
           author="true"
           version="true"
           use="true"
           windowtitle="Hello World API Documentation Version: ${version}">
 </javadoc>
  </target>
 
  <target name="run" depends="jar,docs">
   <!-- run the class -->
   <java classname="${runclass}">
         <!-- add a command line arg: <arg value="-h"/> -->
         <classpath>
     <!-- use the value of the ${classpath} property in the classpath -->
        <pathelement path="${classpath}"/>
     <!-- include all jar files  -->
        <fileset dir="${include}">
            <include name="**/*.jar"/>
        </fileset>
        <fileset dir="${lib}">
            <include name="**/*.jar"/>
        </fileset>
  </classpath>
       </java>

  </target>
 
  <target name="clean">
    <!-- Delete the ${build} and ${lib} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${lib}"/>
 <delete dir="${docs}"/>
  </target>
</project>

 



More Code Samples



  
home products services partners company support contact
Copyright 2006 © Zrinity Inc. All rights reserved.     View our privacy policy         September 7, 2010