as a WAR file"> <war destfile="${name}.war" webxml="${web.dir}/WEB-INF/web.xml"> <fileset dir="${web.dir}"> <include name="**/*.*"/> </fileset> </war> <copy todir="${deploy.path}" preservelastmodified="true"> <fileset dir="."> <include name="*.war"/> </fileset> </copy> </target> <target name="buildtests" description="Compile test tree java files"> <mkdir dir="${build.dir}"/> <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true"> <src path="${test.dir}"/> <classpath refid="master-classpath"/> </javac> </target> <target name="tests" depends="build, buildtests" description="Run tests"> <junit printsummary="on" fork="false" haltonfailure="false" failureproperty="tests.failed" showoutput="true"> <classpath refid="master-classpath"/> <formatter type="brief" usefile="false"/> <batchtest> <fileset dir="${build.dir}"> <include name="**/*Tests.*"/> </fileset> </batchtest> </junit> <fail if="tests.failed"> tests.failed=${tests.failed} *********************************************************** *********************************************************** **** One or more tests failed! Check the output ... **** *********************************************************** *********************************************************** </fail> </target> <!-- ============================================================== --><!-- Tomcat tasks - remove these if you don't have Tomcat installed --><!-- ============================================================== --> <path id="catalina-ant-classpath"> <!-- We need the Catalina jars for Tomcat --> <!-- * for other app servers - check the docs --> <fileset dir="${appserver.lib}"> <include name="catalina-ant.jar"/> </fileset> </path> <taskdef name="install" classname="org.apache.catalina.ant.InstallTask"> <classpath refid="catalina-ant-classpath"/> </taskdef> <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask"> <classpath refid="catalina-ant-classpath"/> </taskdef> <taskdef name="list" classname="org.apache.catalina.ant.ListTask"> <classpath refid="catalina-ant-classpath"/> </taskdef> <taskdef name="start" classname="org.apache.catalina.ant.StartTask"> <classpath refid="catalina-ant-classpath"/> </taskdef> <taskdef name="stop" classname="org.apache.catalina.ant.StopTask"> <classpath refid="catalina-ant-classpath"/> </taskdef> <target name="install" description="Install application in Tomcat"> <install url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${name}" war="${name}"/> </target> <target name="reload" description="Reload application in Tomcat"> <reload url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${name}"/> </target> <target name="start" description="Start Tomcat application"> <start url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${name}"/> </target> <target name="stop" description="Stop Tomcat application"> <stop url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${name}"/> </target> <target name="list" description="List Tomcat applications"> <list url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}"/> </target><!-- End Tomcat tasks --></project>Se voce estiver utilizando um servidor de aplicacao web diferente, poderaremover as tarefas especificas do Tomcat no final do script. Voce tera queconfiar no recurso de hot deploy do servidor ou parar e iniciar a aplicacaomanualmente.Se voce estiver usando uma IDE podera encontrar erros relatados pela IDE nobuild.xml, como os targets do Tomcat. Voce pode ignora-los. A listagem dearquivos acima esta correta.O script de construcao Ant acima contem todas as targets que vamos precisarpara reduzir nossos esforcos de desenvolvimento. Nao explicaremos o script em detalhe. Vocepode copiar este codigo e colar em um novo arquivo chamado build.xml na raizde sua arvore de diretorios. Precisamos tambem de um arquivo build.propertiesque devera ser personalizado de acordo com a instalacao do servidor. Estearquivo deve estar no mesmo diretorio do build.xml. No exemplo abaixocoloquei o caminho de instalacao do Tomcat no meu computador.'springapp/build.properties':# Ant properties for building thespringappappserver.home=${user.home}/Desenvolvimento/Servidores/apache-tomcat-6.0.35# for Tomcat 5 use$appserver.home}/server/lib# for Tomcat 6 use$appserver.home}/libappserver.lib=${appserver.home}/libdeploy.path=${appserver.home}/webappstomcat.manager.url=http://localhost:8080/managertomcat.manager.username=tomcattomcat.manager.password=s3cretSe estiver em um sistema onde voce nao e o proprietario (owner) da instalacao do Tomcat, entao oproprietario deve conceder-lhe acesso total a pasta webapps ou o deve criaruma nova pasta chamada springapp na pasta webapps da instalacao do Tomcat edar-lhe plenos direitos de acesso. No linux execute o commando chmod a+rwxspringapp para dar plenos direitos a pasta springapp.Para criar um usuario chamado tomcat com senha s3cret,adicione a entrada abaixo no arquivo 'appserver.home/conf/tomcat-users.xml'.<tomcat-users> <role rolename="manager"> <user password="s3cret" roles="manager" username="tomcat"></user></role></tomcat-users>Agora execute o ant para certificar-se de que tudo esta ok. Abra oterminal (ou prompt), entre na pasta springapp e execute ant.Aultima coisa que precisamos fazer e criar e implantar o aplicativo. Para istobasta executar o Ant especificando deploy ou deploywar.1.4. Verificar se a aplicacao estafuncionandoInicie o Tomcat executando '${appserver.home}/bin/startup.bat' (ou sh startup.sh).Para ter a certeza deque