The moose likes Java in General and the fly likes Jar  Manifest  ClassPath Atribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jar  Manifest  ClassPath Atribute" Watch "Jar  Manifest  ClassPath Atribute" New topic

Jar Manifest ClassPath Atribute

Mercurio Savedra

Joined: Dec 04, 2005
Posts: 25
Hi friends

I am right now developing a java application that is compressed as jar. The application uses a postgresql jar and log4j jar, then as the sun tutorial mention I write in the manifest file the classpath attribute. I use absolute path for each jar and write too the attribute that indicate the main class. Then I generate my jar file and put it in a folder in C called PrinterControl .

Here is my manisfet file content

Manifest-Version: 1.0
Class-Path: C:/jars/log4j-1.2.15.jar C:/jars/postgresql-8.3-603.jdbc2.jar
Main-Class: com.mercantil.printer_control.controller.Process_Controller

When I try to run the application this crashed and return a message that say java.lang.NodefClassFound
I think that the class loader can�t find the main class .

I decided to create a folder inside C:\ PrinterControl called lib and inside lib I moved the jars and changed the manifest just like this:

Manifest-Version: 1.0
Class-Path: lib/log4j-1.2.15.jar lib/postgresql-8.3-603.jdbc2.jar
Main-Class: com.mercantil.printer_control.controller.Process_Controller

Generating the jar and running and simply everything is Ok

Someone can explain why in my first choice it didn�t work?. Why it lost the classpath for jar internal classes and didn�t found the main class ?

I would appreciate a lot your comments and help
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15094

There is one peculiarity that you have to take into account with regard to the manifest file in a JAR: It must end with a blank line. If there is no blank line at the end of the manifest, then the last line in the manifest will be ignored.

So if you don't have a blank line as the last line in the manifest, then your Main-Class line will be ignored, and it won't work.

It's strange, but that's how it works... See this page in Sun's tutorial for more information.

I don't know why it doesn't work when you specify absolute paths for the JAR files. But doing so is not a good idea, especially if you use a Windows-specific absolute path (beginning with C - it will make your application not work on non-Windows OS'es.
[ May 16, 2008: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Jar Manifest ClassPath Atribute
It's not a secret anymore!