[ start | index | login ]

Manifest

Created by mpecher. Last edited by mpecher, 5 years and 354 days ago. Viewed 1,406 times. #5
[diff] [history] [edit] [rdf]
labels
attachments

Manifest file Basics

Sun has some good info on the Manifest file for a jar: >>http://java.sun.com/docs/books/tutorial/deployment/jar/manifestindex.html
When you create a JAR file, it automatically receives a default manifest file. There can be only one manifest file in an archive, and it always has the pathname
META-INF/MANIFEST.MF

Known issues

Warning: The text file from which you are creating the manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.

Application's Entry Point

If you have an application bundled in a JAR file, you need some way to indicate which class within the JAR file is your application's entry point. You provide this information with the Main-Class header in the manifest, which has the general form:
Main-Class: classname
eg: Main-Class: MyPackage.MyClass

Seeting Classpath in a Jar

You may need to reference classes in other JAR files from within a JAR file.
You specify classes to include in the Class-Path header field in the manifest file. The Class-Path header takes the following form:
Class-Path: jar1-name jar2-name directory-name/jar3-name
By using the Class-Path header in the manifest, you can avoid having to specify a long -classpath flag when invoking Java to run the your application.   Note: The Class-Path header points to classes or JAR files on the local file system, not JAR files within the JAR file or classes on the network. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

We want to load classes in MyUtils.jar into the class path for use in MyJar.jar. These two JAR files are in the same directory.

Manifest-Version: 1.0
  Class-Path: MyUtils.jar
  Created-By: 1.5.0_01 (Sun Microsystems Inc.)
The classes in MyUtils.jar are now loaded into the class path when you run MyJar.jar.

Specification

A specification (of the manifest format is part of the on-line JDK documentation at >>http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#JAR%20Manifest
no comments | post comment

Menu:
Java & J2EE
Development
Books

Help:
Help FAQ
Formatting


< February 2012 >
SunMonTueWedThuFriSat
1234
567891011
12131415161718
19202122232425
26272829


Logged in Users: (1)
… and 10 Guests.



Disclaimer: Views and opinions are that of the individual author, and not that of Marand Custom Solutions. This site is an open forum for technical content, and the company accepts no liability for any content or view expressed.