Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In the startup scripts generated by gradle's application plugin, how can I have the program name passed in to the application?

Tags:

java

gradle

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.

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.

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?

like image 625
Laurence Gonsalves Avatar asked Jan 17 '18 17:01

Laurence Gonsalves


1 Answers

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

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

Documentation on customizing the start scripts can be found here.

like image 129
jihor Avatar answered Oct 11 '22 19:10

jihor