7

Jar is ignoring my manifest file and replaces it with auto-generated manifest.

my manifest is :

Manifest-Version: 1.0 
Created-By: Student Name 
Main-Class: ua.sumdu.j2se.studentName.tasks.PrintMonth

(with empty line)

cmd:

jar -cvf build/tasks.jar MANIFEST.MF build\classes\ua\sumdu\j2se\studentName\tasks\*.class

and as a result if I open jar file with winrar, there would be:

build
META-INF
MANIFEST.MF - my manifest

if i place manifest into META-INF and execute

jar -cvf build/tasks.jar META-INF/MANIFEST.MF build\classes\ua\sumdu\j2se\studentName\tasks\*.class

in my META-INF folder will be 2 manifests.

What's going on?

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
ovnia
  • 2,412
  • 4
  • 33
  • 54

5 Answers5

9

Use the M option to disable the default META-INF/MANIFEST.MF, or use the m option to explicitly specify your own (documentation).

Brett Kail
  • 33,593
  • 2
  • 85
  • 90
4

One more thing: the order of jar options matters. If you put m first, f second, then jar arguments need to go in the same order: manifest-file jar-file, and vice versa.

The line in jar help I missed first:

The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.
Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91
3

Also check that the last line of your manifest ends with a new line or carriage feed. I did not have a new line at the end of my manifest and this made it appear to be omitted.

I see you have (with empty line). But I arrived at this answer without one.

NeverCast
  • 66
  • 4
2

Try this jar -cmvf MANIFEST.MF build/tasks.jar build\classes\ua\sumdu\j2se\studentName\tasks\*.class

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
1

Step 1.

Compile Main.java.

javac Main.java

Step 2.

Create MANIFEST.MF.

Manifest-Version: 1.0
Main-Class: Main

Step 3.

Create app.jar.

jar cmvf MANIFEST.MF app.jar Main.class

Step 4.

Run app.jar.

java -jar app.jar
mamadaliev
  • 145
  • 2
  • 9