简体   繁体   English

使用 gradle 将清单文件添加到 jar

[英]add manifest file to jar with gradle

How to add manifest files in jar files?如何在 jar 文件中添加清单文件?

plugins {
        id 'java'
        id 'application'
}

application {
        mainClassName = 'com.Main'
}

jar {
        from "MANIFEST.MF"
}

sourceCompatibility = 11

when I try to execute jar, I get following :当我尝试执行 jar 时,我得到以下信息:

% java -jar tmpApp.jar % java -jar tmpApp.jar
no main manifest attribute, in tmpApp.jar tmpApp.jar 中没有主清单属性

Here's how you can generate an appropriate manifest file in the jar task of your build:以下是在构建的jar任务中生成适当清单文件的方法:

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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM