Arquivo de build ANT genérico
Autor: Marcelo | Publicado: 2008-11-27T16:58:00-02:00

Segue um arquivo ANT para build automatizado que fiz para um trabalho na faculdade. Serve para projetos simples, onde o código fonte fica na pasta /src, as libs em /lib. Será criado um .zip com os arquivos .jar do programa, das libs, e do código fonte na pasta do projeto. Arquivos criados temporariamente são apagados.Basta criar um arquivo build.xml na raiz do projeto, e definir algumas variáveis no arquivo antes de executar.Observação: apesar de uma parte do código não aparecer por causa do layout, basta selecionar tudo que a cópia sairá correta.&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot; ?&gt; &lt;project name=&quot;build&quot; default=&quot;zip&quot; basedir=&quot;.&quot;&gt; &lt;!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --&gt;  &lt;!-- nome do programa --&gt;   &lt;property name=&quot;app.name&quot; value=&quot;scheduler&quot; /&gt;  &lt;!-- classe principal do programa --&gt;   &lt;property name=&quot;main.class&quot; value=&quot;br.ufsc.ine5616.scheduler.MainScheduler&quot; /&gt;   &lt;!-- classpath: definir todas as libs, pois o JRE não aceita wildcards --&gt;   &lt;property name=&quot;classpath&quot; value=&quot;lib/forms-1.2.1.jar lib/looks-2.2.1.jar&quot; /&gt; &lt;!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --&gt;   &lt;!-- diretorio de fontes --&gt; &lt;property name=&quot;src&quot; value=&quot;${basedir}/src&quot; /&gt; &lt;!-- diretorio de libs --&gt; &lt;property name=&quot;lib&quot; value=&quot;${basedir}/lib&quot; /&gt;  &lt;!-- diretorios temporarios --&gt; &lt;property name=&quot;build&quot; value=&quot;${basedir}/classes&quot; /&gt; &lt;property name=&quot;jar&quot; value=&quot;${basedir}/jar&quot; /&gt; &lt;property name=&quot;dist&quot; value=&quot;${basedir}/dist&quot; /&gt;  &lt;tstamp&gt;    &lt;format property=&quot;timestamp&quot; pattern=&quot;dd-MMM-yyyy HH:mm:ss&quot; /&gt; &lt;/tstamp&gt; &lt;target name=&quot;create&quot; description=&quot;Creates output folders&quot;&gt;  &lt;echo&gt;[${app.name}] Create&lt;/echo&gt;  &lt;mkdir dir=&quot;${build}&quot; /&gt;  &lt;mkdir dir=&quot;${jar}&quot; /&gt;  &lt;mkdir dir=&quot;${dist}&quot; /&gt; &lt;/target&gt; &lt;target name=&quot;compile&quot; depends=&quot;create&quot; description=&quot;Compiles the source&quot;&gt;  &lt;echo&gt;[${app.name}] Compile&lt;/echo&gt;  &lt;javac srcdir=&quot;${src}&quot; destdir=&quot;${build}&quot; &gt;   &lt;classpath&gt;    &lt;fileset dir=&quot;${lib}&quot;&gt;     &lt;include name=&quot;**/*.jar&quot; /&gt;    &lt;/fileset&gt;   &lt;/classpath&gt;   &lt;/javac&gt; &lt;/target&gt;  &lt;target name=&quot;jar&quot; depends=&quot;compile&quot; description=&quot;Creates the jar&quot;&gt;  &lt;echo&gt;[${app.name}] Jar&lt;/echo&gt;  &lt;jar destfile=&quot;${jar}/${app.name}.jar&quot; basedir=&quot;${build}&quot;&gt;   &lt;manifest&gt;    &lt;attribute name=&quot;Implementation-Title&quot; value=&quot;${app.name}&quot;/&gt;    &lt;attribute name=&quot;Main-Class&quot; value=&quot;${main.class}&quot;/&gt;    &lt;attribute name=&quot;Sealed&quot; value=&quot;true&quot;/&gt;    &lt;attribute name=&quot;Class-Path&quot; value=&quot;${classpath}&quot;/&gt;    &lt;attribute name=&quot;Created-On&quot; value=&quot;${timestamp}&quot;/&gt;    &lt;attribute name=&quot;Created-By&quot; value=&quot;${user.name}&quot;/&gt;   &lt;/manifest&gt;  &lt;/jar&gt; &lt;/target&gt;  &lt;target name=&quot;deploy&quot; depends=&quot;jar&quot; description=&quot;Deploys projects and /lib to /dist&quot;&gt;   &lt;echo&gt;[${app.name}] deploy&lt;/echo&gt;   &lt;copy todir=&quot;${dist}/${app.name}&quot; overwrite=&quot;yes&quot;&gt;    &lt;fileset dir=&quot;${jar}&quot; includes=&quot;${app.name}.jar&quot;/&gt;   &lt;/copy&gt;   &lt;copy todir=&quot;${dist}/${app.name}/lib&quot; overwrite=&quot;yes&quot;&gt;    &lt;fileset dir=&quot;${basedir}/lib&quot; includes=&quot;*.jar&quot; /&gt;   &lt;/copy&gt;   &lt;/target&gt; &lt;target name=&quot;deploy-src&quot; description=&quot;Deploys the source files to a .jar file&quot;&gt;  &lt;echo&gt;[${app.name}] deploy - src&lt;/echo&gt;  &lt;jar destfile=&quot;${jar}/${app.name}-src.jar&quot; basedir=&quot;${src}&quot;&gt;   &lt;manifest&gt;    &lt;attribute name=&quot;Implementation-Title&quot; value=&quot;${app.name}&quot;/&gt;    &lt;attribute name=&quot;Created-On&quot; value=&quot;${timestamp}&quot;/&gt;    &lt;attribute name=&quot;Created-By&quot; value=&quot;${user.name}&quot;/&gt;   &lt;/manifest&gt;  &lt;/jar&gt;  &lt;copy todir=&quot;${dist}/${app.name}&quot; overwrite=&quot;yes&quot;&gt;   &lt;fileset dir=&quot;${jar}&quot; includes=&quot;${app.name}-src.jar&quot;/&gt;  &lt;/copy&gt; &lt;/target&gt;  &lt;target name=&quot;zip&quot; depends=&quot;deploy, deploy-src&quot; description=&quot;Creates a .zip with the app&quot;&gt;   &lt;echo&gt;[${app.name}] Zip&lt;/echo&gt;   &lt;delete file=&quot;${app.name}.zip&quot; /&gt;   &lt;zip destfile=&quot;${app.name}.zip&quot; basedir=&quot;${dist}&quot; update=&quot;true&quot; /&gt;   &lt;ant antfile=&quot;${basedir}/build.xml&quot; target=&quot;clean&quot; /&gt; &lt;/target&gt;  &lt;target name=&quot;clean&quot; description=&quot;Cleans the output directories&quot;&gt;  &lt;echo&gt;[${app.name}] Clean&lt;/echo&gt;  &lt;delete dir=&quot;${build}&quot; /&gt;  &lt;delete dir=&quot;${jar}&quot; /&gt;  &lt;delete dir=&quot;${dist}&quot; /&gt; &lt;/target&gt;&lt;/project&gt;