5,138,331 members and growing! (12,729 online)
Email Password   helpLost your password?
Languages » Java » General     Intermediate

Manifest Reader for Ant Tool

By Prasad Khandekar

An Ant task for reading manifest information from a jar file and display it.
Java, Java, Dev

Posted: 3 Mar 2006
Updated: 3 Mar 2006
Views: 8,533
Announcements



Search    
Advanced Search
Sitemap
4 votes for this Article.
Popularity: 1.75 Rating: 2.90 out of 5
1 vote, 25.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
2 votes, 50.0%
4
1 vote, 25.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This article presents a simple but quite useful ant task for reading MANIFEST.MF file contained in a jar and selectively print it's content.

MANIFEST.MF

MANIFEST.MF file is a simple text file containing one or more sections and information related to each section in name value pair format. The major purpose of having this file is that it allows you to define extension and package related data.

Task Usage

To be able to use this task you need to inform ant about it's existence. This can be very easily done by putting follwing script in your ant build file.
<typedef resource="com/freeware/anttasks/antlib.xml">
     <classpath path="${basedir}/antcontrib/mfprinter-1.0.2.jar" />
</typedef>
Once this is done you are ready to use this task in your build script. The following ant script snippet shows a typical usage of this task.
<target name="printinfo" description="Print application details!">
    <manifestreader srcfile="${basedir}/antcontrib/mfprinter-1.0.2.jar">
        <attribute name="Build-Date"                 value="Built On        :"/>
        <section name="com/freeware/anttasks">
            <attribute name="Implementation-Title"   value="Product Name    :"/>
            <attribute name="Implementation-Version" value="Product Version :"/>
            <attribute name="Implementation-Vendor"  value="Copyright       :"/>
        </section>
    </manifestreader>
</target>
The above code snippet will produde following output.
Buildfile: testtask.xml

test:
[manifestreader] Built On        : March 3 2006 at 11:41 AM
[manifestreader] Product Name    : Manifest Printer
[manifestreader] Product Version : 1.0.2
[manifestreader] Copyright       : Khan Information Systems

BUILD SUCCESSFUL
Total time: 0 seconds

Task Parameters

Attribute Description Required
srcfile The full path and name of the jar file whose manifest is to be read Yes

Nested Elements

  • attribute
    One attribute for the manifest file. Those attributes that are not nested into a section will be added to the "Main" section.
    Attribute Description Required
    name the name of the attribute as defined in manifest file. Yes
    value the label text to be used while printing the manifest attribute value. Yes
  • section
    A manifest section - you can nest attribute elements into sections.
    Attribute Description Required
    name the name of the section as defined in manifest file. No, if omitted it will be assumed to be the main section.

Conclusion

Ant tool does provide a task for manifest file creation. This task now compltes the manifest task by providing the read capability. The main motivation behind development of this task was to be able to display certain useful fields from manifest file in situations where the stand alone java service is started by using Ant tool. This can quickly help in determining whether the user of your application is using correct jar file or not.

History

  • March 03, 2006 - First release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Prasad Khandekar


I am a software professional with over 15 years of business applications design and development experience. I have started my software carrier way back in 1993 as a COBOL programmer. Later on switched to FoxPro, Magic, Visual Basic, .NET and today I find myself working in Java.
Occupation: Architect
Company: Reflexis Systems (INDIA) Pvt. Ltd.
Location: India India

Other popular Java articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
  (Refresh) 
Subject  Author Date 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 3 Mar 2006
Editor:
Copyright 2006 by Prasad Khandekar
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project