1 / 19

Premiers pas avec Apache Ant

Premiers pas avec Apache Ant. Par Guillaume BITAUDEAU Le 16/10/2003. Plan de la présentation. Qu’est-ce que c’est ? Pourquoi refaire un Make ? Installation Notions de bases et fonctionnement Exemple Créer sa propre tache Utilisation dans Eclipse Avantages/défauts Bibliographie.

zach
Télécharger la présentation

Premiers pas avec Apache Ant

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Premiers pas avec Apache Ant Par Guillaume BITAUDEAU Le 16/10/2003

  2. Plan de la présentation • Qu’est-ce que c’est ? • Pourquoi refaire un Make ? • Installation • Notions de bases et fonctionnement • Exemple • Créer sa propre tache • Utilisation dans Eclipse • Avantages/défauts • Bibliographie

  3. Qu’est-ce que c’est ? • « Another Neat Tool » … • Un outil ressemblant à Make • Entièrement en java • Réalisé par James Duncan Davidson pour compiler Tomcat • Licence « Apache Software license »

  4. Pourquoi refaire un Make ? • Multi plateforme • Pour les règles utilisées • Pour son fonctionnement • Fichiers XML • Extensible en Java • Peut quand même exécuter une ligne de commandes !!!

  5. Installation • Télécharger la dernière version à partir du site : http://ant.apache.org/ • Décompresser l’archive • Mettre à jour les variables d’environnement : • ANT_HOME=c:\ant • JAVA_HOME=c:\jdk1.2.2 • PATH=%PATH%;%ANT_HOME%\bin

  6. Notions de bases et fonctionnement : les trois types principaux • Un fichier par projet : build.xml • Un « projet » par fichier • <project name="MyProject" default= "monTarget" basedir="."> • Plusieurs « target » par « projet » • <target name="compile" depends="init" description="compile the source " if/unless="maPropIsSet"/ > • Chaque target n’est exécuté qu’une seule fois • Plusieurs « task » par « target » • <taskname id="taskID" attribute1="value1" …/>

  7. Notions de base et fonctionnement : les tasks indispensables (suite) • Les « property » : • 5 méthodes pour les initialiser (valeur, réf, properties/ressource java, environnement) • <property name="maProp" value="dist"/> • <property file="foo.properties"/> • <property environment="env"/> • Non modifiables • Utilisation : • <property file="${maProp}/laSuite"/> • <echo message="Number of Processors = ${env.NUMBER_OF_PROCESSORS}"/>

  8. Notions de base et fonctionnement : les tasks indispensables (suite) • Les « PatternSet » • Utilisation de *,?,**,/ • <patternset id="sources"> <include name="std/**/*.java"/> <exclude name="**/*Test*"/> <includesfile name="${some-other-file}" if="some-other-file"/> <excludesfile name="some-file"/> </patternset> • Attention aux exclusions par défaut

  9. Notions de base et fonctionnement : les tasks indispensables (suite) • Les « Selectors » • <classpath> <fileset dir="lib"> <include name="**/*.jar"/> </fileset> <dirset dir="${build.dir}"> <include name="apps/**/classes"/> <exclude name="apps/**/*Test*"/> </dirset> <filelist dir="leDir" files="foo.xml,bar.xml"> </classpath>

  10. Notions de base et fonctionnement : les tasks indispensables (suite) • Les « token filtrers » • <filter token="year" value="2000"/> <copy todir="${dest.dir}" filtering="true"> <fileset dir="${src.dir}"/> </copy> • Attention aux fichiers non ASCII !!!

  11. Notions de base et fonctionnement : les principales catégories de tasks (fin) • Archive Tasks • Compile Tasks • Deployment Tasks • Documentation Tasks • Execution Tasks • File Tasks • Remote Tasks • Testing Tasks • …

  12. Exemple <project name="MyProject" default="dist" basedir="."> <description> simple example build file </description> <!-- set global properties for this build --> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/> <target name="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <mkdir dir="${build}"/> </target>

  13. Exemple (suite) <target name="compile" depends="init" description="compile the source " > <!-- Compile the java code from ${src} into ${build} --> <javac srcdir="${src}" destdir="${build}"/> </target> <target name="dist" depends="compile" description="generate the distribution" > <!-- Create the distribution directory --> <mkdir dir="${dist}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/> </target>

  14. Exemple (fin) <target name="clean" description="clean up" > <!-- Delete the ${build} and ${dist} directory trees --> <delete dir="${build}"/> <delete dir="${dist}"/> </target> </project>

  15. Créer sa propre tache : le .java import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; public class MyVeryOwnTask extends Task { private String msg; public void init () { //nothing to do } public void execute() throws BuildException { System.out.println(msg); } public void setMessage(String msg) { this.msg = msg; } } 1 2 4 3 (les conversions sont faites par Ant)

  16. Créer sa propre tache : le .xml (fin) <project name="OwnTaskExample" default="main" basedir="."> <taskdef name="mytask" classname="com.mydomain.MyVeryOwnTask"/> <target name="main"> <mytask message="Hello World! MyVeryOwnTask works!"/> </target> </project> • Le .java peut être complété pour : • Supporter l’intégration dans un GUI • Faire des tâches plus complexes

  17. Utilisation dans Eclipse • Editeur spécialisé • Exécution de Ant intégrée à Eclipse

  18. Multi plateforme. Documentations nombreuses sur Internet. Extensible. XML facilement lisible. De plus en plus d’outils comme Eclipse le supportent Outil encore jeune. Compatibilité entre les différentes versions. Performances? Avantages / Défauts

  19. Bibliographie • Pour Ant : • Le Site officiel de Ant : http://ant.apache.org/ • Pour Ant et Eclipse : • Le manuel d’Eclipse • « Développons en java » de Jean Michel DOUDOUX : http://perso.wanadoo.fr/jm.doudoux/java/dejae/indexavecframes.htm

More Related