DOC PREVIEW
DREXEL CS 265 - Ant & Jar

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Ant & JarjarCreating a jarfileCreating a jarfile - exampleExecuting a jarfileAntWhy another build tool?Ant vs MakeSlide 9Who should use Ant?ResourcesLinksKey WordsAnt Detailsbuild.xmlHow to run antbuild.xml ExampleComplex ant build file exampleComplex example (cont.)Ant SetupCommon Ant TasksCommon Tasks (cont)Common Ant Tasks (cont.)Extra TasksExamplesExampleSlide 27Slide 28Slide 29Slide 30Ant & JarAnt – Java-based build toolJar – pkzip archive, that contains metadata (a manifest file) that the JRE understandsjarUse jar utility to create jar filesA compressed, tar'd collection of *.class filesCommand format like tarFile format pkzip, but includes a manifest file MANIFEST.MF (meta-data)Can be added to classpath; JRE searches a jarfile like a directory, for included packagesCreating a jarfileOptions much like tarc – createx – extractu – updateOthersv – verbosef – specify archive filenamem – include manifest info from named fileCreating a jarfile - exampleGiven class files:pokerSuit.class, pokerClient.classCreate the jarfile:$ jar cvf poker.jar poker*.classYou can use unzip -l to look at the contents. Notice the MANIFEST.MF:Archive: poker.jar Length Date Time Name -------- ---- ---- ---- 0 08-06-06 09:30 META-INF/ 120 08-06-06 09:30 META-INF/MANIFEST.MF 670 08-06-06 09:19 pokerClient.class 636 08-06-06 09:19 pokerSuit.class -------- ------- 1426 4 filesExecuting a jarfileJar files can be made executable by adding a Main-Class line to the manifest, and identifying the class that contains maincreate an mf file (poker.mf) w/these lines:Classpath: ./poker.jarMain-Class: pokerClientCreate the jarfile w/this info:$ jar cvfm poker.jar poker.mf *.classTo run:java –jar poker.jarAntA bit like MakeCross-platformExtended w/Java classes, rather than shell-dependent scriptsReads XML configuration filesJava-basedOpen sourceWhy another build tool?Make tools are shell basedDevelopment across multiple platformsAnt vs MakeAnt is Cross PlatformAnt will work on any platform that has a Java VM.Make relies on specific OS shell commandsSyntaxMake has a scary looking syntaxMake tab problemAnt uses XMLself documentingEfficiencyAntPROsFast CompilesPlatform IndependentEasier to use than makeCONsnon-Java projectsWho should use Ant?Use AntIf you don’t already know makeIf you are developing anything cross platformUse Make–If you are a make expert.–Developing applications in non-Java language.ResourcesAnt : the definitive guideISBN: 0596001843Java tools for eXtreme Programming ISBN: 047120708XElectronic resourceAnt add-ons:http://ant.apache.org/external.htmlLinkshttp://ant.apache.org/http://ant.apache.org/resources.htmlhttp://ant.apache.org/manual/index.htmlNice description of the various tags/tasksKey WordsBuild FileCollection of targets (hopefully logical)TargetCollection of tasksCan have dependencies (other targets, etc.)TaskSpecific commands for building, running, etcAnt DetailsAll Ant tasks are defined in a Java classAn example of a particular task would be JAVADOC (see common built-in tasks, later)Ant has a core set of tasks that come with it. Other optional tasks can be downloaded.Ant is very modularized.build.xmlThe default build file Ant looks for-f option allows to specify a different build fileHow to run antant [-f file] [target*]file – config file (build.xml if not supplied)target* - list of targets to be builtE.g.:$ ant test$ ant compile$ ant javadoc$ ant compile javadoc$ antIf you don’t specify, the default is executedbuild.xml Example<project default="compile"> <target name="compile"> <javac srcdir="." /> </target> </project>Simply compiles all *.java files in the current directory (calls javac)Complex ant build file example<project default="all"> <property name="obj-dir" location="obj" /> <property name="lib-dir" location="lib" /> <property name="src-dir" location="src" /><target name="init"> <mkdir dir="${obj-dir}" /> <mkdir dir="${lib-dir}" /> </target> <target name="clean-init"> <delete dir="${obj-dir}" /> <delete dir="${lib-dir}" /> </target><target name="compile" depends="init"> <javac srcdir="${src-dir}" destdir="${obj-dir}" /> </target> <target name="clean-compile"> <delete> <fileset dir="${obj-dir}" includes="**/*.class" /> </delete> </target>Complex example (cont.)<target name="jar" depends="compile"> <jar destfile="${lib-dir}/hello.jar" basedir="${obj-dir}" /> </target> <target name="clean-jar"> <delete file="${lib-dir}/hello.jar" /></target> <target name="run" depends="jar"> <java classname="hello" classpath="${lib-dir}/hello.jar" fork="true" /> </target><target name="all" depends="run"/> <target name="clean" depends="clean-init"/> </project>Ant SetupAnt is installed in /usr/local/bin/antJAVA_HOME variable should be setshould be set to prefix of /bin/javaOn the CS machines:/usr/localOR/opt/java5/jdk1.5.0_06/Common Ant Tasks<javac srcdir=dir [includes=fileList]/>compiles Java source files <java classname=class/> OR<java fork='yes' jar=jar/>runs a Java applicationjavadocgenerates javadoc HTML file from Java source filesmkdircreates a directory and any missing parent directoriesCommon Tasks (cont)movemoves files and directories to a new directory<copy file=src (tofile=dest | todir=destDir) />copies files<delete (file=file | dir=dir ) />deletes given file or dir<echo [file=file] message=msg/> or <echo [file=file]>msg</echo>outputs a message to System.out or fileCommon Ant Tasks (cont.)Gunzipunzips a GZIP fileGzipcreates a GZIP file from a fileJarcreates a JAR file from a set of filesMailsends email using SMTPGetcreates a copy of a remote file at a specified URLcan use http and ftp URLsExtra TasksJUnitruns JUnit testsrequires junit.jar from http://junit.orgFTPlists, gets, puts and deletes files on an FTP serverrequires NetComponents.jarExamplesGiven files foo.java, which extends bar.java,in the current directorycompile all java files in directory:<project default="compile"><target name="compile"><javac srcdir="." /></target></project>Examplecompile only foo and bar:<project default="compile"> <target name="compile" depends='foo,bar'/> <target name="foo" depends='bar'> <javac srcdir='./' includes='foo.java'/> </target> <target name="bar"> <javac srcdir='./'


View Full Document

DREXEL CS 265 - Ant & Jar

Download Ant & Jar
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Ant & Jar and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Ant & Jar 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?