JDev: Including a Class-Path In Your MANIFEST.MF

JAR File

Java Applications can and should be packaged in a Java Archive file (JAR file). This is basically a ZIP file with an additional META-INF directory which contains a file called MANIFEST.MF.

MANIFEST.MF

The MANIFEST.MF file contains a number of entries which I call tags. The most common ones are Manifest-Version, Main-Class, or Class-Path. You'll find Manifest-Version in every MANIFEST.MF file.

Main-Class

The Main-Class tag is useful for an application packaging with the main class defined, but not telling the user. To start the application you usually issue something like java -jar application.jar. One of the well known examples is java -jar oc4j.jar. To specify the Main-Class tag in your MANIFEST.MF you need to include the following line:
Main-Class: path.to.your.application.Main

Class-Path

The Class-Path tag is useful for specifying the list of the libraries application needs to successfully run. You can specify the class path like any other but use the blank character (' ') as the path separator. Ie. no colon (':')or semicolon (';') as for the Un*x/Linux or Win environments, respectively.
To specify the Class-Path tag in your MANIFEST.MF you need to include a line like the following:
Class-Path: lib/ojdbc14.jar lib/log4j.jar

Specifying MANIFEST.MF tags in JDev

JDeveloper offers you two choices to specify your MANIFEST.MF tags. But before you can do this, you have to create a Deployment Profile for your JDev project (New... > General > Deployment Profiles). Once you have this profile in your project, open the Deployment Profile Properties dialog window. Navigate to the Options entry for specifying the tags.

Include the MANIFEST.MF File

To make your specified tags available in your MANIFEST.MF, make sure to select the Include Manifest File (META-INF/MANIFEST.MF) checkbox.

Setting the Main-Class Tag

Since this is one of the most used tags, it got a primary location in the dialog and you get some help to find the right class. To complete the Main Class entry you can either enter the fully qualified class name or use the Browse button to find the right class.

ClassBrowser:
Picture 1: Class Browser window

Setting the Class-Path Tag

To specify the Class-Path tag in JDev you have to define a fragment file to be included in your MANIFEST.MF (or merged into the Manifest file). The fragment file could be in your source files and contains all the tags you'd like to specify.
Class-Path: 
  ../config/
  classes12.jar
  bc4jct.jar
  bc4jdomorcl.jar
  bc4jmt.jar
  commons-beanutils-bean-collections.jar
  commons-beanutils-core.jar
  commons-beanutils.jar
  commons-codec-1.3.jar
  commons-collections-3.1.jar
  commons-configuration-1.2.jar
  commons-digester.jar
  commons-lang-2.0.jar
  commons-logging.jar
  htbclnt.jar
  j2ee/home/oc4jclient.jar
For ease of work, I recommend to have a single line per library.

DeploymentProfile:
Picture 2: Deployment Profile window

Conclusion

This way we're free to specify every possible tag in the MANIFEST.MF. Although this is a workable solution, I wish setting the Class-Path would be much better supported by the Deployment Profile in JDev.

Comments:

Thanks Olaf. That helped me a lot - I couldn't find where to specify the classpath. Note that you have to end the fragment file by a carriage return. Otherwise, the file is not included in the manifest.mf file. Regards, Didier.

Posted by Didier on June 10, 2009 at 07:23 AM CEST #

Hello Olaf, Your "Class-Path Tag" Tip resolved my Problem. I have searched a lot, but you are the only one who delivered the right Answer ! Thanks!

Posted by Furnica on October 01, 2009 at 07:18 AM CEST #

Well... This does not work for 10.1.3.3

Posted by guest on May 25, 2011 at 04:51 AM CEST #

Thanks for descriptions.
I dont understand from talking about Main-Class: path.to.your.application.Main

What should I do instead of the "path.to.your.application.Main"?

please help me!

Posted by guest on December 19, 2011 at 02:19 AM CET #

Simply replace path.to.your.application.Main with the fully qualified class name of your main class.

Posted by Olaf on December 19, 2011 at 04:40 AM CET #

What if we have some jar files included in the jar package we create as a complete package? I mean, for the classpath tag I have tried below, but no one worked:
Class-Path: lib.jar
Class-Path: /lib.jar
Class-Path: ./lib.jar

NOTE: In my jar package I have the lib.jar in the root, and checked it with suitable programs..

Posted by Suphi ÇEVİKER on March 20, 2012 at 09:11 AM CET #

The Class-Path tag is used be the JDK for JAR files outside the JAR file your are building. If you don't want this, you should include the content of the required JAR files in your distributed JAR file as well, ie., one single file with every class you need.

Posted by Olaf Heimburger on March 30, 2012 at 07:51 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