# CreateStartScripts

API Documentation: | `CreateStartScripts`

Creates start scripts for launching JVM applications.

Example:

    task createStartScripts(type: CreateStartScripts) {
      outputDir = file('build/sample')
      mainClass = 'org.gradle.test.Main'
      applicationName = 'myApp'
      classpath = files('path/to/some.jar')
    }

Note: the Gradle `"application"` plugin adds a pre-configured task of this type named `"startScripts"`.

The task generates separate scripts targeted at Microsoft Windows environments and UNIX-like environments (e.g. Linux, macOS). The actual generation is implemented by the `CreateStartScripts.getWindowsStartScriptGenerator()` and `CreateStartScripts.getUnixStartScriptGenerator()` properties, of type `ScriptGenerator`.

Example:

    task createStartScripts(type: CreateStartScripts) {
      unixStartScriptGenerator = new CustomUnixStartScriptGenerator()
      windowsStartScriptGenerator = new CustomWindowsStartScriptGenerator()
    }

    class CustomUnixStartScriptGenerator implements ScriptGenerator {
      void generateScript(JavaAppStartScriptGenerationDetails details, Writer destination) {
        // implementation
      }
    }

    class CustomWindowsStartScriptGenerator implements ScriptGenerator {
      void generateScript(JavaAppStartScriptGenerationDetails details, Writer destination) {
        // implementation
      }
    }

The default generators are of the type `TemplateBasedScriptGenerator`, with default templates. This templates can be changed via the `TemplateBasedScriptGenerator.setTemplate(org.gradle.api.resources.TextResource)` method.

The default implementations used by this task use Groovy's SimpleTemplateEngine to parse the template, with the following variables available:

- `applicationName`
- `optsEnvironmentVar`
- `exitEnvironmentVar`
- `mainModule`
- `mainClass`
- `executableDir`
- `defaultJvmOpts`
- `appNameSystemProperty`
- `appHomeRelativePath`
- `classpath`

Example:

    task createStartScripts(type: CreateStartScripts) {
      unixStartScriptGenerator.template = resources.text.fromFile('customUnixStartScript.txt')
      windowsStartScriptGenerator.template = resources.text.fromFile('customWindowsStartScript.txt')
    }

### Properties

Property | Description
`applicationName` | The application's name.
`classpath` | The class path for the application.
`defaultJvmOpts` | The application's default JVM options. Defaults to an empty list.
`executableDir` | The directory to write the scripts into in the distribution.
`mainClass` | Incubating The main class name used to start the Java application. Use this property instead of `CreateStartScripts.getMainClassName()` and `CreateStartScripts.setMainClassName(java.lang.String)`.
`mainModule` | Incubating The main module name used to start the modular Java application.
`optsEnvironmentVar` | The environment variable to use to provide additional options to the JVM.
`outputDir` | The directory to write the scripts into.
`unixStartScriptGenerator` | The UNIX-like start script generator.
`windowsStartScriptGenerator` | The Windows start script generator.

### Methods

No methods

### Script blocks

No script blocks

### Property details

#### `String` `applicationName`

The application's name.

#### `FileCollection` `classpath`

The class path for the application.

#### ``Iterable`<`String`>` `defaultJvmOpts`

The application's default JVM options. Defaults to an empty list.

#### `String` `executableDir`

The directory to write the scripts into in the distribution.

#### ``Property`<`String`>` `mainClass`

Note: This property is incubating and may change in a future version of Gradle.

The main class name used to start the Java application. Use this property instead of `CreateStartScripts.getMainClassName()` and `CreateStartScripts.setMainClassName(java.lang.String)`.

#### ``Property`<`String`>` `mainModule`

Note: This property is incubating and may change in a future version of Gradle.

The main module name used to start the modular Java application.

#### `String` `optsEnvironmentVar`

The environment variable to use to provide additional options to the JVM.

#### `File` `outputDir`

The directory to write the scripts into.

#### `ScriptGenerator` `unixStartScriptGenerator`

The UNIX-like start script generator.

Defaults to an implementation of `TemplateBasedScriptGenerator`.

#### `ScriptGenerator` `windowsStartScriptGenerator`

The Windows start script generator.

Defaults to an implementation of `TemplateBasedScriptGenerator`.