Reputation: 927
How to add manifest files in jar files?
plugins {
id 'java'
id 'application'
}
application {
mainClassName = 'com.Main'
}
jar {
from "MANIFEST.MF"
}
sourceCompatibility = 11
when I try to execute jar, I get following :
% java -jar tmpApp.jar
no main manifest attribute, in tmpApp.jar
Upvotes: 5
Views: 12705
Reputation: 16408
Here’s how you can generate an appropriate manifest file in the jar
task of your build:
jar {
manifest {
attributes 'Main-Class': application.mainClassName
}
}
Alternatively, you can use a custom file for the manifest:
jar {
manifest {
from 'MANIFEST.MF'
}
}
You can even create a mixture of both:
jar {
manifest {
// take the existing file as a basis for the generated manifest:
from 'MANIFEST.MF'
// add an attribute to the generated manifest file:
attributes 'Main-Class': application.mainClassName
}
}
Upvotes: 13