Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Jar Manifest ClassPath Atribute

Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Java Cowboy
Posts: 16084
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
no wonder he is so sad, he hasn't seen this tiny ad:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic