Tuesday, 5 April 2016

How to use Archive tasks in Ant ?


GUnzip / BUnzip2
Expands a resource packed using GZip or BZip2.
If dest is omitted, the parent dir of src is taken.

Examples
<gunzip src="test.tar.gz" mce_src="test.tar.gz" mce_src="test.tar.gz" />
<bunzip2 src="test.tar.bz2" mce_src="test.tar.bz2" mce_src="test.tar.bz2" />
<gunzip src="test.tar.gz" mce_src="test.tar.gz" mce_src="test.tar.gz" dest="test2.tar" />
<gunzip src="test.tar.gz" mce_src="test.tar.gz" mce_src="test.tar.gz" dest="subdir" />
<gunzip dest=".">
   <url url="http://example.org/archive.tar.gz"/>
</gunzip>


GZip/BZip2
Packs a resource using the GZip or BZip2 algorithm. The output file is only generated if it doesn't exist.

<gzip src="test.tar" mce_src="test.tar" mce_src="test.tar"
      destfile="test.tar.gz"/>
<bzip2 src="test.tar" mce_src="test.tar" mce_src="test.tar"
       destfile="test.tar.bz2"/>
<gzip destfile="archive.tar.gz">
   <url url="http://example.org/archive.tar"/>
</gzip>


Cab
It creates Microsoft cab archive files. It is invoked similar to the jar or zip tasks.
This task will work on Windows using the external cabarc tool (provided by Microsoft) which must be located in your executable path.
Example
<cab cabfile="${dist}/manual.cab" basedir="htdocs/manual" />
<cab cabfile="${dist}/manual.cab" basedir="htdocs/manual"
     excludes="mydocs/**, **/todo.html" />


Ear
An extension of the Jar task with special treatment for files that should end up in an Enterprise Application archive.
Example
<ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
      <fileset dir="${build.dir}" includes="*.jar,*.war"/>
</ear>


Jar
Jars a set of files. The basedir attribute is the reference directory from where to jar.
Example
<jar destfile="${dist}/lib/app.jar" basedir="${build}/classes"/>
<jar destfile="${dist}/lib/app.jar" basedir="${build}/classes"
     excludes="**/Test.class" />
<jar destfile="${dist}/lib/app.jar" basedir="${build}/classes"
     includes="mypackage/test/**" excludes="**/Test.class"/>

<jar destfile="${dist}/lib/app.jar">
    <fileset dir="${build}/classes" excludes="**/Test.class" />
    <fileset dir="${src}/resources"/>
</jar>

<jar destfile="build/main/checksites.jar">
    <fileset dir="build/main/classes"/>
    <zipfileset includes="**/*.class">
      <fileset dir="lib/main" includes="**/*.jar"/>
    </zipfileset>
    <manifest>
      <attribute name="Main-Class" value="com.acme.checksites.Main"/>
    </manifest>
</jar>

 
Manifest
Creates a manifest file.
This task can be used to write a Manifest file, optionally replacing or updating an existing file.
<manifest file="MANIFEST.MF">
  <attribute name="Built-By" value="${user.name}"/>
  <section name="common">
    <attribute name="Specification-Title" value="Example"/>
    <attribute name="Specification-Version" value="${version}"/>
    <attribute name="Implementation-Version" value="${version} ${TODAY}"/>
  </section>
  <section name="common/class1.class">
    <attribute name="Sealed" value="false"/>
  </section>
</manifest>


Rpm
This task is for invoking the rpm executable to build a RedHat Package Manager Linux installation file. The task currently only works on Linux or other Unix platforms with rpm support.
<rpm specFile="example.spec"  topDir="build/rpm" cleanBuildDir="true" failOnError="true" />


SignJar
Signs JAR files with the jarsigner command line tool.
It will take a named file in the jar attribute, and an optional destDir or signedJar attribute.
<signjar jar="${dist}/lib/ant.jar" alias="apache-group" storepass ="secret"/>


Tar
Creates a tar archive.
The basedir attribute is the reference directory from where to tar.
<tar destfile="${dist}/manual.tar" basedir="htdocs/manual"/>

Then, gzip task can be used to make gunzip file from tar file.
<gzip destfile="${dist}/manual.tar.gz" src="${dist}/manual.tar" mce_src="${dist}/manual.tar" mce_src="${dist}/manual.tar"/>

<tar destfile="${dist}/manual.tar" basedir="htdocs/manual" excludes="mydocs/**, **/todo.html" />

<tar destfile="${basedir}/docs.tar">
  <tarfileset dir="${dir.src}/docs" fullpath="/usr/doc/ant/README" preserveLeadingSlashes="true">
    <include name="readme.txt"/>
  </tarfileset>
  <tarfileset dir="${dir.src}/docs" prefix="/usr/doc/ant" preserveLeadingSlashes="true">
    <include name="*.html"/>
  </tarfileset>
</tar>

<tar destfile= "release.tar.gz" compression="gzip">
  <zipfileset src="release.zip" mce_src="release.zip" mce_src="release.zip"/>
</tar>


Unjar | Untar | Unwar | Unzip
Unzips a zip-, war-, or jar file.
<unzip src="${tomcat_src}/tools-src.zip"
       mce_src="${tomcat_src}/tools-src.zip"
       mce_src="${tomcat_src}/tools-src.zip" dest="${tools.home}"/>

<gunzip src="tools.tar.gz" mce_src="tools.tar.gz"
        mce_src = "tools.tar.gz"/>

<untar src="tools.tar" mce_src="tools.tar" mce_src="tools.tar"
       dest="${tools.home}"/>

<unzip src="${tomcat_src}/tools-src.zip"
       mce_src="${tomcat_src}/tools-src.zip"
       mce_src="${tomcat_src}/tools-src.zip" dest="${tools.home}">
    <patternset>
        <include name="**/*.java"/>
        <exclude name="**/Test*.java"/>
    </patternset>
</unzip>

<unzip dest="${tools.home}">
    <patternset>
        <include name="**/*.java"/>
        <exclude name="**/Test*.java"/>
    </patternset>
    <fileset dir=".">
        <include name="**/*.zip"/>
        <exclude name="**/tmp*.zip"/>
    </fileset>
</unzip>

<unzip src="apache-ant-bin.zip" mce_src="apache-ant-bin.zip"
       mce_src="apache-ant-bin.zip" dest="${tools.home}">
    <patternset>
        <include name="apache-ant/lib/ant.jar"/>
    </patternset>
    <mapper type="flatten"/>
</unzip>


War
An extension of the Jar task with special treatment for files that should end up in the WEB-INF/lib, WEB-INF/classes or WEB-INFdirectories of the Web Application Archive.
Assume the following structure in the project's base directory.

thirdparty/libs/jdbc1.jar, jdbc2.jar
build/main/com/myco/myapp/Servlet.class
src/metadata/myapp.xml
src/html/myapp/index.html
src/jsp/myapp/front.jsp
src/graphics/images/gifs/small/logo.gif
src/graphics/images/gifs/large/logo.gif

<war destfile="myapp.war" webxml="src/metadata/myapp.xml">
  <fileset dir="src/html/myapp"/>
  <fileset dir="src/jsp/myapp"/>
  <lib dir="thirdparty/libs">
    <exclude name="jdbc1.jar"/>
  </lib>
  <classes dir="build/main"/>
  <zipfileset dir="src/graphics/images/gifs" prefix="images"/>
</war>

war file myapp.war created, will consist of :
WEB-INF/web.xml
WEB-INF/lib/jdbc2.jar
WEB-INF/classes/com/myco/myapp/Servlet.class
META-INF/MANIFEST.MF
index.html
front.jsp
images/small/logo.gif
images/large/logo.gif


Zip
Creates a zip file.
The basedir attribute is the reference directory from where to zip.

<zip destfile="${dist}/manual.zip" basedir="htdocs/manual" />
<zip destfile="${dist}/manual.zip" basedir="htdocs/manual"
     update="true" />
<zip destfile="${dist}/manual.zip" basedir="htdocs/manual"
     excludes="mydocs/**, **/todo.html" />
<zip destfile="${dist}/manual.zip" basedir="htdocs/manual"
     includes="api/**/*.html" excludes="**/todo.html" />

<zip destfile="${dist}/manual.zip">
    <fileset dir="htdocs/manual"/>
    <fileset dir="." includes="ChangeLog.txt"/>
</zip>

<zip destfile="${dist}/manual.zip">
    <zipfileset dir="htdocs/manual" prefix="docs/user-guide"/>
    <zipfileset dir="." includes="ChangeLog27.txt"
                fullpath="docs/ChangeLog.txt"/>
    <zipfileset src="examples.zip" mce_src="examples.zip"
                mce_src="examples.zip" includes="**/*.html"
                prefix="docs/examples"/>
</zip>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.