Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

ANT

1,960 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

ANT

  1. 1. ANT [email_address]
  2. 2. Cosa è ant <ul><li>Ant è un tool scritto in Java che permette di organizzare la creazione e il deploy di classi java in ambienti distribuiti e multipiattaforma </li></ul><ul><li>Ant è basato su un unico programma che legge le azioni da intraprendere da un file XML (default: build.xml) </li></ul><ul><li>È open source e freeware, scaricabile dal sito: </li></ul><ul><li>http://ant.apache.org </li></ul>
  3. 3. Vantaggi di ant <ul><li>È possibile compilare le classi utilizzando il jdk installato sul sistema finale </li></ul><ul><li>Non è necessario avere un IDE installato o creare lunghi file batch per compilare le classi con tutti i riferimenti alle librerie necessarie </li></ul><ul><li>È possibile automatizzare l’avvio o il deploy delle applicazioni al termine della compilazione </li></ul><ul><li>È possibile far creare con semplici passaggi degli archivi .jar, .war o .ear per il deployment delle classi </li></ul>
  4. 4. Installazione di ant <ul><li>Scaricare ant e decomrimerlo in una cartella (consiglio la stessa in cui è installato Tomcat) </li></ul><ul><li>Inserire il path della cartella di ant nella variabile ANT_HOME </li></ul><ul><li>Inserire nella variabile PATH il percorso ANT_HOME/bin </li></ul>
  5. 5. Un primo programma in ant <ul><li>Creare il file build.xml contenente il seguente testo: </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><project name= &quot;MyProject&quot; default= &quot;myTarget&quot; basedir= &quot;.&quot; > </li></ul><ul><li><target name= &quot;myTarget&quot; depends= &quot;myTarget.check&quot; if= &quot;myTarget.run&quot; > </li></ul><ul><li><echo> Files foo.txt and bar.txt are present. </echo> </li></ul><ul><li></target> </li></ul><ul><li><target name= &quot;myTarget.check&quot; > </li></ul><ul><li><condition property= &quot;myTarget.run&quot; > </li></ul><ul><li><and> </li></ul><ul><li><available file= &quot;foo.txt&quot; /> </li></ul><ul><li><available file= &quot;bar.txt&quot; /> </li></ul><ul><li></and> </li></ul><ul><li></condition> </li></ul><ul><li></target> </li></ul><ul><li></project> </li></ul>
  6. 6. Eseguire ant <ul><li>Aprire una shell di comandi e spostarsi nella directory in cui si è creato il file build.xml </li></ul><ul><li>Eseguire il comando </li></ul><ul><ul><li># ant </li></ul></ul><ul><li>Se non esistono i file foo.txt e bar.txt non si vedrà la scritta </li></ul><ul><li>Files foo.txt and bar.txt are present. </li></ul><ul><li>Creare i file e rieseguire ant </li></ul>
  7. 7. Classpath <classpath> <pathelement path= &quot;${classpath}&quot; /> <fileset dir= &quot;lib&quot; > <include name= &quot;**/*.jar&quot; /> </fileset> <pathelement location= &quot;classes&quot; /> <dirset dir= &quot;${build.dir}&quot; > <include name= &quot;apps/**/classes&quot; /> <exclude name= &quot;apps/**/*Test*&quot; /> </dirset> <filelist refid= &quot;third-party_jars&quot; /> </classpath>
  8. 8. Tag java <ul><li>Il tag java è utilizzato per eseguire una classe: </li></ul><java classname= &quot;test.Main&quot; > <arg value= &quot;-h&quot; /> <classpath> <pathelement location= &quot;dist/test.jar&quot; /> <pathelement path= &quot;${java.class.path}&quot; /> </classpath> </java>
  9. 9. Tag javac <javac srcdir= &quot;${src}&quot; destdir= &quot;${build}&quot; /> Il tag javac è usato per compilare una o più classi: Anche con svariati attributi di compilazione: <javac sourcepath= &quot;&quot; srcdir= &quot;${src}&quot; destdir= &quot;${build}&quot; > <include name= &quot;**/*.java&quot; /> <exclude name= &quot;**/Example.java&quot; /> </javac>
  10. 10. Tag property the url from which to read properties. <property url=&quot;http://www.mysite.com/bla/foo.properties&quot;/> url the filename of the property file. <property file=&quot;ant-global.properties&quot;/> <property file=&quot;${user.home}/ant-global.properties&quot;/> file the resource name of the property file. <property resource=&quot;foo.properties&quot;/> resource Sets the property to the absolute filename of the given file. <property name=&quot;src&quot; location=&quot;src&quot;/> location the value of the property. <property name=&quot;compile&quot; value=&quot;2&quot;/> value the name of the property to set. <property name=&quot;src&quot; … name Description Attribute
  11. 11. Un semplice buildfile <project name= &quot;MyProject&quot; default= &quot;dist&quot; basedir= &quot;.&quot; > <description> simple example build file </description> <!-- set global properties for this build --> <property name= &quot;src&quot; location= &quot;src&quot; /> <property name= &quot;build&quot; location= &quot;build&quot; /> <property name= &quot;dist&quot; location= &quot;dist&quot; /> <target name= &quot;init&quot; > <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure --> <mkdir dir= &quot;${build}&quot; /> </target>
  12. 12. Un semplice buildfile <target name= &quot;compile&quot; depends= &quot;init&quot; description= &quot;compile&quot; > <!-- Compile the java code from ${src} into ${build} --> <javac srcdir= &quot;${src}&quot; destdir= &quot;${build}&quot; /> </target> <target name= &quot;dist&quot; depends= &quot;compile&quot; description= &quot;generate the distribution&quot; > <!-- Create the distribution directory --> <mkdir dir= &quot;${dist}/lib&quot; /> <!– put ${build}into the MyProject-${DSTAMP}.jar file --> <jar jarfile= &quot;${dist}/lib/MyProject-${DSTAMP}.jar&quot; basedir= &quot;${build}&quot; /> </target>
  13. 13. Un semplice buildfile <target name= &quot;clean&quot; description= &quot;clean up&quot; > <!-- Delete the ${build} and ${dist} directory --> <delete dir= &quot;${build}&quot; /> <delete dir= &quot;${dist}&quot; /> </target> </project>
  14. 14. Diversi target <ul><li>Eseguendo il comando </li></ul><ul><li># ant <target> </li></ul><ul><li>Dove <target> è il nome di un target definito nel file build.xml, viene eseguito solo quel particolare target. </li></ul>
  15. 15. Esempio buildfile con più target <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <project name= &quot;EJB Mail BottegaVerde Project&quot; default= &quot;ejb-jar&quot; basedir= &quot;.&quot; > <target name= &quot;init&quot; > <!-- Project Directories --> <property name= &quot;src.dir&quot; value= &quot;${basedir}/ejbModule&quot; /> <property name= &quot;classes.dir&quot; value= &quot;${basedir}/classes&quot; /> <property name= &quot;resources.dir&quot; value= &quot;${basedir}/resources&quot; /> <!-- Archive names --> <property name= &quot;archive.name&quot; value= &quot;bottegaVerdeMail&quot; /> <!-- Sets the jboss directory from the local environment --> <property environment= &quot;env&quot; /> <!-- Override with your JBoss server dist location if JBOSS_DIST is not set --> <property name= &quot;jboss.dist&quot; value= &quot;${env.JBOSS_DIST}&quot; /> </target> <target name= &quot;compile&quot; depends= &quot;init&quot; > <mkdir dir= &quot;${classes.dir}&quot; /> <javac srcdir= &quot;${src.dir}&quot; destdir= &quot;${classes.dir}&quot; debug= &quot;on&quot; deprecation= &quot;on&quot; optimize= &quot;off&quot; > <classpath> <fileset dir= &quot;${jboss.dist}/client&quot; includes= &quot;**/*.jar&quot; /> </classpath> </javac> </target>
  16. 16. Esempio buildfile con più target <target name= &quot;ejb-jar&quot; depends= &quot;compile&quot; > <delete file= &quot;${classes.dir}/${archive.name}.jar&quot; /> <jar jarfile= &quot;${classes.dir}/${archive.name}.jar&quot; > <fileset dir= &quot;${classes.dir}&quot; excludes= &quot;**/*Client.class&quot; /> <zipfileset dir= &quot;${resources.dir}&quot; prefix= &quot;META-INF&quot; includes= &quot;*.xml&quot; /> </jar> </target> <target name= &quot;deploy&quot; depends= &quot;ejb-jar&quot; > <copy file= &quot;${classes.dir}/${archive.name}.jar&quot; todir= &quot;${env.JBOSS_DIST}/server/default/deploy&quot; /> </target> <target name= &quot;undeploy&quot; > <delete file= &quot;${env.JBOSS_DIST}/server/default/deploy/${archive.name}.jar&quot; /> </target> <target name= &quot;testStateless&quot; depends= &quot;compile&quot; > <java classname= “org.ubitek.stateless.TestStatelessClient&quot; fork= &quot;yes&quot; > <classpath> <pathelement location= &quot;${classes.dir}&quot; /> <pathelement location= &quot;${resources.dir}&quot; /> <fileset dir= &quot;${jboss.dist}/client&quot; includes= &quot;**/*.jar&quot; /> </classpath> </java> </target>
  17. 17. Esempio buildfile con più target <target name= &quot;testStateful&quot; depends= &quot;compile&quot; > <java classname= “org.ubitek.stateful.TestStatefulClient&quot; fork= &quot;yes&quot; > <classpath> <pathelement location= &quot;${classes.dir}&quot; /> <pathelement location= &quot;${resources.dir}&quot; /> <fileset dir= &quot;${jboss.dist}/client&quot; includes= &quot;**/*.jar&quot; /> </classpath> </java> </target> <target name= &quot;testBMP&quot; depends= &quot;compile&quot; > <java classname= &quot;org.ubitek.bmp.CDClient&quot; fork= &quot;yes&quot; > <classpath> <pathelement location= &quot;${classes.dir}&quot; /> <pathelement location= &quot;${resources.dir}&quot; /> <fileset dir= &quot;${jboss.dist}/client&quot; includes= &quot;**/*.jar&quot; /> </classpath> </java> </target> <target name= &quot;testCMP&quot; depends= &quot;compile&quot; > <java classname= &quot;com.imolinfo.entity.cmp20.CDClient&quot; fork= &quot;yes&quot; > <classpath> <pathelement location= &quot;${classes.dir}&quot; /> <pathelement location= &quot;${resources.dir}&quot; /> <fileset dir= &quot;${jboss.dist}/client&quot; includes= &quot;**/*.jar&quot; /> </classpath> </java> </target>
  18. 18. Esempio buildfile con più target <target name= &quot;testMD&quot; depends= &quot;compile&quot; > <java classname= “org.ubitek.message.TestMDBean&quot; fork= &quot;yes&quot; > <classpath> <pathelement location= &quot;${classes.dir}&quot; /> <pathelement location= &quot;${resources.dir}&quot; /> <fileset dir= &quot;${jboss.dist}/client&quot; includes= &quot;**/*.jar&quot; /> </classpath> </java> </target> <target name= &quot;clean&quot; depends= &quot;init&quot; > <delete dir= &quot;${classes.dir}&quot; /> </target> </project>

×