Wednesday, May 28, 2008

How do you modify the Manifest File of a JAR?

Question: How do you modify the Manifest File of a JAR?

Answer: Let's discuss first why would we need to modify a Manifest File? Well... there can be various reason. One being the change of Entry Point of a stand-alone application. The Main-Class header of the Manifest file contains the Class Name whose main() method wil be used to start the execution. If you want to specify any other Class as the Entry Point, you may need to modify the Manifest File. Similarly, the Manifest File may be modified to add any other special purpose headers with appropriate values.

How to modify it?

We can only merge other info to the already existing manifest file of a JAR. 'jar' tool automatically creates one default manifest file and we can add any extra info to the contents of the default manifest file. Subsequently, if we want to add even more info then also we need to follow the same procedure and that extra info will be added to the contents of the existing manifest file.

For adding any extra info we need to create a text file having the details in a proper format. Once the text file is ready then we can use the 'jar' tool with 'm' option to add that info to the contents of the already existing manifest file. Proper format means the data you have in the text file should form the contents of a valid manifest file and every line of the text file must end with a new line or a carriage return.

Caution: don't forget to add a new line after the last line of the text file as well otherwise that line may not be parsed properly.

Command for adding some info right at the time of creating the JAR file can be like this:-

jar cfm JArFileName.jar ManifestAdditionTextFile.txt InputFilesOfTheJAR

Here option 'c' means 'create a new JAR', option 'f' means 'the output should go to a file and not to the standard output', and option 'm' means 'merge info to the already existing (in this case default) manifest file'.

The order of options 'm' and 'f' must be in the same order as you provide the corresponding arguments to the command. 'c' option doesn't require any argument and normally comes as the first one.



amit said...

I have gone through this blog ,and found the explanation really excellent ,Can you please post the detailed ans of these question

1)What are the various methods to improve the performance of query

2)What are the new features has been added in oracle 9i

Thanking you in advance geek

Geek said...

Amit: Questions noted. They are really good questions. Will post the answers soon. Thanks for sharing them with us. Keep visiting/posting!

Geek said...

Amit: answer to your first question posted. Please visit the below URL to get to the answer:-

I'll post the answer to your second question soon. Sorry for the delay. Keep visiting/posting!

Geek said...

Amit: answer to your second question posted at the below URL:

amit said...

Geek I have gone through the illustration of both the question .I am completely satisfied with the ans

Anil Philip said...

I think you left out the 'update' option ufm