What's this? A JAR File with MANIFEST.MF Only?

Maybe some of you have already wondered what this is.

JAR File

A JAR file is a Java Archive based on the popular ZIP file specification from PKWARE. If a JAR file includes a META-INF directory, the contents will be interpreted by the JVM.

META-INF/MAINFEST.MF

The MANIFEST.MF is used to define extensions and package information for the JAR file.

Manifest Name Value Pairs

The Manifest file can contain a number of Name Value pairs in the form of name: value. Each of theses pairs is delimited by a newline. Popular names are Main-Class or Class-Path.

The Trick

If your application consists of a number of JAR files and you have different entry points, aka Main Classes, you can save a lot of maintenance time by packaging everything as usual and create special JAR files for the entry points.

Sample MANIFEST.MF

Here is a MANIFEST.MF snippet taken from OC4J to explain this:
Manifest-Version: 1.0
Created-By: 1.3.1 (Sun Microsystems, Inc.)
Main-Class: com.evermind.client.orion.Oc4jAdminConsole
Class-Path: oc4j.jar
This way, you refer to the Main Class packaged somewhere in the Class Path (ie. oc4j.jar in this case). You'll find this snippet in the MANIFEST.MF of admin.jar.

It is important to note that the Class Path is relative to the working directory of the JAR file.

Usage

Using such a JAR file is easy (shown for OC4J's admin.jar):
java -jar admin.jar

Comments:

hi, Can you tell how we can add multiple entries in class-path from jdeveloper. Regards, Imran

Posted by imran raza khan on November 27, 2007 at 05:27 PM CET #

Imran, will write an entry on this. --olaf

Posted by Olaf Heimburger on November 27, 2007 at 05:47 PM CET #

How to set jar file version and how to get jar vesion in tomcat server console

Posted by guest on July 28, 2008 at 03:09 AM CEST #

How to get jar version for the user defined jar in tomcat server console

Posted by shan on July 28, 2008 at 03:10 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This is my blog for things I found useful during my work as Senior Solution Architect for Identity Management and Service-oriented Architecture at Oracle. All text expressed on this blog is my own opinion and not related to my employer.

Search

Top Tags
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today