Created
November 18, 2018 09:58
-
-
Save JeanRibes/796f2451e4974595304adddcad808842 to your computer and use it in GitHub Desktop.
Boilerplate Ant pour des projets Java simples avec dépendances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project name="chat" default="all" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant"> | |
<!-- Paramètres du projet --> | |
<property name="projet.sources.dir" value="src"/> | |
<property name="projet.lib.dir" value="lib"/> | |
<property name="projet.jar.file" value="release.jar"/> | |
<property name="projet.bin.dir" value="out"/> | |
<property name="projet.class.main" value="MaClassePrincipale" /> | |
<!-- Dépendances du projet--> | |
<target name="resolve" depends="install-ivy,setup" description="Use ivy to resolve classpaths"> | |
<ivy:retrieve pathid="libs.path"> | |
<dependency org="org.nom...." name="librairie" rev="version" /> | |
</ivy:retrieve> | |
</target> | |
<!-- Definition du classpath du projet --> | |
<path id="projet.classpath"> | |
<fileset dir="${projet.lib.dir}"> | |
<include name="*.jar" /> | |
</fileset> | |
<pathelement location="${projet.bin.dir}" /> | |
</path> | |
<!-- Compilation des classes du projet --> | |
<target name="compile" description="Compilation"> | |
<javac srcdir="${projet.sources.dir}" destdir="${projet.bin.dir}" debug="off" optimize="on" deprecation="on" | |
includeantruntime="false" encoding="utf-8" classpathref="libs.path"> | |
<classpath refid="projet.classpath" /> | |
</javac> | |
</target> | |
<!--création du JAR--> | |
<target name="package" description="Création du JAR" depends=""> | |
<jar jarfile="${projet.jar.file}" basedir="${projet.bin.dir}" compress="true"> | |
<restrict> <!-- inclut les librairies dans le JAR--> | |
<archives> | |
<zips> | |
<fileset dir="${projet.lib.dir}" includes="**/*.jar" excludes="*sources*,*javadoc*" /> | |
</zips> | |
</archives> | |
</restrict> | |
<manifest> | |
<attribute name="Main-Class" value="${projet.class.main}" /> | |
</manifest> | |
</jar> | |
</target> | |
<!--nettoyage--> | |
<target name="clean" description="Supprime tous les 'generated'"> | |
<delete dir="${projet.bin.dir}" verbose="true" /> | |
<delete file="${projet.jar.file}" /> | |
</target> | |
<target name="setup"> | |
<mkdir dir="${projet.lib.dir}" /> | |
<mkdir dir="${projet.bin.dir}" /> | |
</target> | |
<target name="run"> | |
<java classname="${projet.class.main}" fork="true"> | |
<classpath refid="projet.classpath" /> | |
</java> | |
</target> | |
<available file="${projet.jar.file}" property="projet.jar.built" /> | |
<target name="run-jar" if="projet.jar.built"> | |
<java jar="${projet.jar.file}" fork="true" /> | |
</target> | |
<target name="all" description="Compilation et exécution" depends="clean,setup,resolve,compile,package,run" /> | |
<!--Install IVY https://stackoverflow.com/questions/26650590/how-to-add-dependency-to-ant-project voir --> | |
<available classname="org.apache.ivy.Main" property="ivy.installed" /> | |
<target name="install-ivy" description="Install ivy" unless="ivy.installed"> | |
<mkdir dir="${user.home}/.ant/lib" /> | |
<get dest="${user.home}/.ant/lib/ivy.jar" | |
src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar" /> | |
<fail message="Ivy has been installed. Run the build again" /> | |
<!--fin de la magie--> | |
</target> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment