在gradle的应用程序插件生成的启动脚本中

在gradle的应用程序插件生成的启动脚本中

本文介绍了在gradle的应用程序插件生成的启动脚本中,如何将程序名称传递给应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行gradle应用程序插件的 installDist 任务会创建目录 build/install/ my-application-name /bin ,其中包含包装脚本, my-application-name my-application-name .bat .运行这些脚本之一将运行应用程序,并将传递给这些脚本的参数传递给基础应用程序.

Executing the gradle application plugin's installDist task creates a directory build/install/my-application-name/bin that contains wrapper scripts, my-application-name and my-application-name.bat. Running either of these scripts runs the application, and arguments passed to these scripts are passed to the underlying application.

在UNIX shell脚本中,您可以使用 $ 0 访问用于执行程序的名称.实际上,gradle生成的启动脚本的UNIX版本多次使用 $ 0 .

In UNIX shell scripts you can access the name that was used to execute the program as $0. In fact, the UNIX version of the gradle-generated startup script uses $0 several times.

如何配置gradle应用程序插件,以便这些脚本将 $ 0 的值(以及Windows上与Windows等效的任何值)传递给基础应用程序,也许作为Java系统属性?

How can I configure the gradle application plugin such that these scripts will pass the value of $0 (and whatever the Windows equivalent is on Windows) into the underlying application, perhaps as a Java system property?

推荐答案

在Linux( $ 0 )和Windows(%0 ),生成自定义脚本的最直接方法是为各个启动脚本生成器:

Since parameter for obtaining the name of the script being run is referenced differently in Linux($0) and in Windows(%0), the most straightforward way to generate custom scripts would be to use separate custom templates for the respective start script generators:

startScripts {
  unixStartScriptGenerator.template = resources.text.fromFile('unixStartScript.txt')
  windowsStartScriptGenerator.template = resources.text.fromFile('windowsStartScript.txt')
}

易于获取默认模板,例如 unixStartScriptGenerator.template.asString()

The default templates are easy to obtain invoking e.g. unixStartScriptGenerator.template.asString()

可以在此处找到有关自定义启动脚本的文档.

Documentation on customizing the start scripts can be found here.

这篇关于在gradle的应用程序插件生成的启动脚本中,如何将程序名称传递给应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:34