• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Jar Manifest ClassPath Atribute

 
Greenhorn
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
88
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 ]
 
I AM MIGHTY! Especially when I hold this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic