This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Jar File Not Accepting my Classpath As specified in the manifest.mf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jar File Not Accepting my Classpath As specified in the manifest.mf" Watch "Jar File Not Accepting my Classpath As specified in the manifest.mf" New topic
Author

Jar File Not Accepting my Classpath As specified in the manifest.mf

Chetan Pandey
Ranch Hand

Joined: Aug 01, 2005
Posts: 31
Hi All:

I think this is a MANIFEST.MF syntax Issue.

I have a Jar File dict.jar.

When I run it using :

java -jar dict.jar


It doesnt work and throws an Exception that one of the Class Files from a dependency jar is missing.

However, if I unzip everything and then run it using the following syntax:

java -cp ./lib/*; com.dictionary.dict.MWSktEngDictionary


it works.

My MANIFEST.MF looks likes the following:



Thanks.

Chetan


PS. Also, if you guys dont mind, I can never run a JAR File on my Windows Vista directly by clicking on it, I always have to go to the Cmd Prompt and do
java -jar name.jar


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38043
    
  22
That classpath in the manifest looks suspect.
Set up an association between .jar and javaw (or javaw.exe) in Windows.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Campbell Ritchie wrote:That classpath in the manifest looks suspect.

In particular the back-slashes. Try using ordinary slashes to separate files.

Also I notice you're using the Java 6 version of the classpath which accepts "*" to mean "all jars in the directory". Perhaps that doesn't work in jar manifests. Anyway you've only got one helper jar so it shouldn't be too hard to name it specifically in the manifest.
Chetan Pandey
Ranch Hand

Joined: Aug 01, 2005
Posts: 31
Hi:

I have tried every combination for the Class-Path


Class-Path: .//lib//sandhi.jar
Class-Path: ./lib/sandhi.jar;
Class-Path: /lib/sandhi.jar
Class-Path: lib/sandhi.jar
Class-Path: lib/sandhi.jar;


Each Time I am told the Dependency from sandhi.jar is missing.

Also, I set an association with .jar file to open with javaw, this ends up giving me a msg:

Couldnot find the Main Class: jarFIleName.jar !!!


Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Does your manifest file end with a new line character?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Chetan Pandey
Ranch Hand

Joined: Aug 01, 2005
Posts: 31
Yes it ends with a NewLine Character.

So, in EditPlus I see four lines.

The first three lines have text and the fourth line is an empty line
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Chetan Pandey wrote:
Hi:

I have tried every combination for the Class-Path


Class-Path: .//lib//sandhi.jar
Class-Path: ./lib/sandhi.jar;
Class-Path: /lib/sandhi.jar
Class-Path: lib/sandhi.jar
Class-Path: lib/sandhi.jar;


Each Time I am told the Dependency from sandhi.jar is missing.


Did you know that what you have put there means that if the jar file is in directory X, then you need have a directory X/lib containing the sandhi.jar? That's different to your example where you used the -classpath option; in that case the "./lib" is relative to the current working directory.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38043
    
  22
I presume you have been through tutorials, etc?
Chetan Pandey
Ranch Hand

Joined: Aug 01, 2005
Posts: 31
Actually the Tutorials clarified something which I had been unclear for a long long time.

Note: The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.


So that implies their is no native out-of-the-box mechanism in Java to read jar from within the jar.

And yes when my java - jar myjar.jar were working , it was located on the same folder which also had the /lib folder.

But moving the myJar.jar to another place, the jar invocation didnt work.

Thanks all for your help, so I have now learnt a important tip on classpaths in Jar Files.

Regards,

Chetan
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

You might want to consider OneJar then
http://one-jar.sourceforge.net/
 
 
subject: Jar File Not Accepting my Classpath As specified in the manifest.mf
 
Similar Threads
Jar Files: Kill me NOW.
SCJD- problem making jar - project from Andrew Monkhouse and Terry Camerlengo book
Jar file help
Jar - Manifest.mf - Class-Path Attribute
Problems creating a Jar file