• Post Reply Bookmark Topic Watch Topic
  • New Topic

Main-Class: Alice in .\META-INF\MANIFEST.MF  RSS feed

 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried repeatedly to figure out how to get this in manifest.file

I can get the jar tool to archive, although not exactly the way I would like to do it. The mainifest is then in the archive, but to edit the manifest - I have to unpack the jar archive.

I want to specifiy this on the command line.

Alice is the name of the class where the main() is that the entire application should be run from.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't specify the main class (or any other Manifest contents) on the command line; you put them in a stub manifest file and supply the file on the "jar" command line. To edit the manifest file, or any file in a jar, you do indeed have to re-jar the whole thing with the new files.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the Jar trail of the Java Tutorial.

You can put the Main-class line in a text file, specify that text file as the manifest on the jar command line and the jar command includes that with the manifest stuff it adds.

I'm not aware of a way to specify Main-class on the command line. The jar tool documentation pointed to the tutorial.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[EFH]: You can't specify the main class (or any other Manifest contents) on the command line; you put them in a stub manifest file and supply the file on the "jar" command line. To edit the manifest file, or any file in a jar, you do indeed have to re-jar the whole thing with the new files.

You don't actually have to re-jar the whole thing - you can use update mode:

This either adds or updates the Main-Class attribute in test.jar's manifest, setting it to class Foo.

In JDK 6, there is a new command option to do this in one step, without creating an extra temp file:
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:



That must be a quick way to write a file from the command line, under the Unice.

Also, when I opened the file in binary mode in my editor, there were characters showing up that did not show up in open/text-mode.

Quite a bit more than an operating system would need for a file header, I assumed it had something to do with the archiving protocol. The question, in part though not stated, is that the jar tool can more than understand this data that is not explained to me and I can just grab the manifest file from the last build, make the appropriate entry - and jumping around from one compiler version to another will not confuse the jar tool, correct ?

Also, correct syntax:

Main-Class: Alice

Correct ? Is it picky about spaces ?

eg:

  Main-Class   :    Alice

Or something of that nature.
[ November 26, 2006: Message edited by: Nicholas Jordan ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[NJ]: That must be a quick way to write a file from the command line, under the Unice.

It works on my Windows 2000 system too, if I drop the quotes. But usually I just use a Cygwin shell so I don't have to think as much about Unix/Windows differences, except for filepaths mostly.

[NJ]: Also, when I opened the file in binary mode in my editor, there were characters showing up that did not show up in open/text-mode.

OK. Depends what system and what editor you're using, I suppose. But the manifest file should be treated as a text file anyway, I think, so this is probably a non-issue. You can create the text file any way you like - whatever works on your system.

[NJ]: Quite a bit more than an operating system would need for a file header, I assumed it had something to do with the archiving protocol. The question, in part though not stated, is that the jar tool can more than understand this data that is not explained to me and I can just grab the manifest file from the last build, make the appropreiate entry - and jumping around from one compiler version to another will not confuse the jar tool, correct ?

The jar tool does a little more than just archiving - in particular it has a bit of custom logic for handling manifest files differently than other files. Changing compiler versions shouldn't bother the jar tool, as far as I know. That's more of an issue between compiler and JVM, e.g. if you compile for 1.5 and try to run on a 1.4 JVM - you can't. In comparison, hte jar tool could care less what compiler version you're using. As far as I know, anyway.

[NJ]: Also, correct syntax:

Main-Class: Alice

Correct ? Is it picky about spaces ?


I doubt it. Personally I just use a single space after the :, none before, and it just works. If I were really curious I would consult the jar command documentation which leads in turn to the JAR manifest docs. Or, well, I'd just try it and see what happens. Thus far though, I've been content to just use the standard spacing I saw in the first example I found when I googled "jar manifest".
[ November 25, 2006: Message edited by: Jim Yingst ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!