Hey, I'm working through the Java Developer Exam study guide - chapter 8, compiling and packaging the application. Page 320 explains the role of the manifest file and goes on to give the content which tells the JVM where to start running the application from... ok, I understand all that. Managed to create the JAR file but when I try to run the application, the message on command prompt reads.... 'Failed to load Main-Class manifest attribute from sampleproject .jar' The Manifest file I made was in notepad but I changed the file extention to type .MF I read an article on modifying a manifest file....
The Jar tool's m option allows you to add information to the default manifest during creation of a JAR file. You must first prepare a text file containing the information you wish to add to the default manifest. You can then use the Jar tool's m option to add the information in your file to the default manifest. The basic command has this format: jar cmf manifest-addition jar-file input-file(s)
So, in that case, shouldn't my own file have a .txt extension? Hope you guys can help Bob [ March 27, 2004: Message edited by: Bob Chandler ]
Hi Bob, The name and extension of the manifest file that you create can be anything you like. You can name it "ProjectManifest.doc" if you really wanted to (although it would probably confuse the examiner, so I wouldn't recommend it ) When you run the "jar cmf parm2 parm3 parm3 ... parmN" command, the jar application reads the order of the options (in my case cmf). The first option (c) tells it to create a jar file, the second option (m) tells it that there is a manifest, and the third option tells it that you are specifying the name of the jar file to be created. The jar program then expects parm2 and parm3 to correspond to the second and third options. So the second option was 'm' for manifest, therefore parm2 must be the name of the manifest file; option 3 was 'f' for file, therefore parm3 must be the name of the jar file. If the order was different (if I specfied "jar cfm parm2 parm3 parm3 ... parmN") then option 2 is 'f' for filename, therefore parm2 must be the jar filename. The important bit is that if you specify the manifest filename, then the jar command will look for whatever filename you give it. Jar does not care what you name it, or where it is: it just assumes it is a plain text file. Now - as for your real problem. Try adding a blank line to the end of your manifest file. Java sometimes has a problem reading that file at runtime if it does not have a trailing blank line. Otherwise, please post the contents of your manifest file and the command line you are using to create the jar file. Regards, Andrew
Try adding a blank line to the end of your manifest file. Java sometimes has a problem reading that file at runtime if it does not have a trailing blank line.
How wierd is that? I checked the order of params which was ok - then I tried adding the blank line as you suggested.....well, I can't speak....it worked! Cheers mate btw, does this rule apply to any other file types in other contexts? just curious... Bob (not crazy after all) Chandler
author and jackaroo
btw, does this rule apply to any other file types in other contexts? just curious...
Which rule? The "add a blank line" concept sometimes applies. There are two cases where it can be worth trying: if you are using an editor that appends a Ctrl-Z to the end of a text file (legacy Microsoft OS requirement), or when using an application that only works when reading complete lines (so it processes the line when it gets a line feed character). In any case, it is an easy enough change to make to your text file to see whether it fixes your problem. The "any extension is fine" rule also sometimes applies. Most applications do not care what the extension of a file is - why should they: it is just data after all. Most applications work on the concept of looking at a magic cookie at the start of a file to determine what the file type is. Looking at my Linux system, I can see that it has records for 1556 such magic numbers. There are of course exceptions: some programs do require you to use a specific extension (e.g. the 'java' and 'javac' commands), some programs make it difficult to use anything but their preferred extensions (try saving something in Microsoft Notepad without the ".txt" extension - it can be done, but it is difficult). Most programs have a default extension to make life easier for the user (e.g. Microsoft Word will default to trying to load files with extension '.doc' (but then totally ignores what the real type of data in that file is). Regards, Andrew
Joined: Jan 13, 2004
Andrew apologies - my question wasn't clear... The 'rule' or concept I was referring to was indeed the blank line at the end of a file. So thanks for the explanation, small issues like this one may seem 'a detail hardly worth mentioning' to the more advanced programmer/developer, but is something that had me scratching my head for days - very frustrating! (grateful) Bob
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com