« Resource Leaks Made Easy | Main | Blog Tagged »

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 (2)

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.

Furnica:

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!

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on January 3, 2008 10:37 AM.

The previous post in this blog was Resource Leaks Made Easy.

The next post in this blog is Blog Tagged.

Many more can be found on the main index page or by looking through the archives.

Top Tags

Powered by
Movable Type and Oracle