File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Class-Path variable in manifest file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class-Path variable in manifest file" Watch "Class-Path variable in manifest file" New topic
Author

Class-Path variable in manifest file

Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
Hi All,

I am trying to create a jar file which is custom utility. I need to package some extra 3rd party jars along with this jar & I am adding the same as part of manifest file when creating the custom jar file.

So here is the manifest file

---------------manifest.mf--------------------
Manifest-Version: 1.0
Created-By: Test User
Main-Class: au.com.test.integration.EventListener.class
Class-Path: activation-1.0.2.jar commons-codec-1.3.jar others.jar
-----------------------------------

Now when i run the jar utility something like this
_________________________________________

jar cfm testlistener.jar manifest.mf *.*
_________________________________________

So in the packaged testlistener.jar the manifest.mf under META-INF looks like this
---------------manifest.mf--------------------
Manifest-Version: 1.0
Created-By: Test User
Main-Class: au.com.test.integration.EventListener.class
-----------------------------------

It just skips the Class-Path attribute when creating the custom jar file.
Can anyone let me know if the above is the right way for doing the same.

Also i wanted to know if i create a separate folder called lib for all teh helper jars to my custom jar file then how do i put the same in my Class-Path attribute of Manifest.MF.
I tried to find the same but did not get much help on the same. How do i append the folder name in front of the jar file path.

Do let me know your comments on the same.

Regards,

Udayan
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14117
    
  16

I just found this in the tutorial:

Warning : The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.

Does your manifest file end with a carriage return?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
Hi Jesper,

Thanks for the reply. That worked.

But the only thing is now I see the jar utility adding the manifest file at 2 locations. One is from where I run the jar command so that gets added to the jar file & it also adds one manifest.mf under the META-INF folder. Ideally we need only one manifest.mf file as part of the package jar & i.e. the file under META-INF folder. How do i ignore the source manifest.mf being bundled as part of the jar & only keep the generated one - the one under META-INF.

Also I would like to know if we can add other external files say log4j.properties , xsl files, dtd files etc which is used by the main class as part of the jar & make our main class look for these files in the jar itself & do not need to actually put it on the classpath of the machine where we are supposed to execute the program unit.

Do post your response.


Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class-Path variable in manifest file