使用 Gradle 创建可运行的 JAR [英] Creating runnable JAR with Gradle

查看:40
本文介绍了使用 Gradle 创建可运行的 JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我通过 Eclipse 的导出..."功能创建了可运行的 JAR 文件,但现在我切换到 IntelliJ IDEA 和 Gradle 以实现构建自动化.

Until now I created runnable JAR files via the Eclipse "Export..." functionallity but now I switched to IntelliJ IDEA and Gradle for build automation.

这里的一些文章建议使用应用程序"插件,但这并没有完全导致我预期的结果(只是一个 JAR,没有启动脚本或类似的东西).

Some articles here suggest the "application" plugin, but this does not entirely lead to the result I expected (just a JAR, no start scripts or anything like this).

如何获得与 Eclipse 使用导出..."对话框相同的结果?

How can I achieve the same result Eclipse does with the "Export..." dialog?

推荐答案

可执行 jar 文件只是一个 jar 文件,在其清单中包含一个 Main-Class 条目.所以你只需要配置 jar 任务 以便在其清单中添加此条目:

An executable jar file is just a jar file containing a Main-Class entry in its manifest. So you just need to configure the jar task in order to add this entry in its manifest:

jar {
    manifest {
        attributes 'Main-Class': 'com.foo.bar.MainClass'
    }
}

您可能还需要在清单中添加类路径条目,但方法相同.

You might also need to add classpath entries in the manifest, but that would be done the same way.

参见 http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html

这篇关于使用 Gradle 创建可运行的 JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆