用Gradle创建可运行的JAR

用Gradle创建可运行的JAR

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

问题描述

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

这里提出了应用程序插件,但这并不完全导致我期望的结果(只是一个JAR,没有启动脚本或类似的东西)。



如何可以Eclipse与Export ...对话框实现的结果相同吗?

解决方案

可执行的jar文件只是一个jar文件在其清单中包含Main-Class条目的文件。因此,您只需配置,以便在清单中添加此条目:

  jar {
清单{
属性'Main-Class':'com.foo.bar.MainClass'
}
}

您可能还需要在清单中添加类路径条目,但这样做也是一样。



请参阅

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

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).

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

解决方案

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.

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

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

08-20 18:46