Friday 19 June 2009

Manifest File Generator

There are many times when we encounter cases requiring us to write small programs which can be invoked using a bat file utility. How do we do that.. simple create an executable jar file and write a bat file to invoke th esame from command prompt. All that you need to do to make a jar file "Executable" is to create a manifest.emf which contains the class path and the location of main(). Here is a sample Manifest file:
Manifest-Version: 1.0
Class-Path: mgapi.jar rvconfig.jar THEMD.jar THEOE.jar THEOM.jar THETHE.jar THETransport.jar tibrvj.jar tibrvjsd.jar tibrvjweb.jar tibrvnative.jar tibrvnativesd.jar
Main-Class: com.ubsw.moap.publisher.MoapPublisher
If you have a look at the "Class-Path" attribute it contains list of all jar files referenced separated by a space " ". What happens when you have a project which references say 40 jar files. This line will become too long and you executable jar file will not work (it throws a stupid array out of bounds exception i guess !!!). So, what's the solution??? Well you need to create a bat file in the following format:
Manifest-Version: 1.0
Created-By: kumarprc
Signature-Version: v1.0.0
Class-Path: lib/activation.jar
__lib/ant.jar
__lib/axis-ant.jar
__lib/axis.jar ... and so on note that the trick lies in keeping two spaces " " before start of next line. and Finally ending with
__lib/xercesImpl-5.5.12.jar
__lib/xml-apis-5.5.12.jar
__lib/xsdlib.jar
Main-Class: com.ubs.sats.TestManager.TestRunner

To create this manifest file manually is too much pain and trusting eclipse to do it for you (packaging.. creating jar and manifest) generally results in "Class not found error" heartburn. So what i do is create a lib dir in my project and keep all my jar files there. Then i use the following program to generate the Manifest.mf file. You can modify the source code to make other fine adjustments.



Free free to contact me for .java file (Easier copy/paste :D)