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
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.