Support embedded jar initialization scripts
Update the Maven and Gradle plugin to generate fully executable jar files on Unix like machines. A launcher bash script is added to the front of the jar file which handles execution. The default execution script will either launch the application or handle init.d service operations (start/stop/restart) depending on if the application is executed directly, or via a symlink to init.d. See gh-1117
This commit is contained in:
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.boot.gradle
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.loader.tools.Layout
|
||||
import org.springframework.boot.loader.tools.Layouts
|
||||
|
||||
@@ -130,4 +133,21 @@ public class SpringBootPluginExtension {
|
||||
*/
|
||||
boolean applyExcludeRules = true;
|
||||
|
||||
/**
|
||||
* If a fully executable jar (for *nix machines) should be generated by prepending a
|
||||
* launch script to the jar.
|
||||
*/
|
||||
boolean executable = true;
|
||||
|
||||
/**
|
||||
* The embedded launch script to prepend to the front of the jar if it is fully
|
||||
* executable. If not specified the 'Spring Boot' default script will be used.
|
||||
*/
|
||||
File embeddedLaunchScript;
|
||||
|
||||
/**
|
||||
* Properties that should be expanded in the embedded launch script.
|
||||
*/
|
||||
Map<String,String> embeddedLaunchScriptProperties;
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.gradle.api.tasks.bundling.Jar;
|
||||
import org.springframework.boot.gradle.SpringBootPluginExtension;
|
||||
import org.springframework.boot.loader.tools.DefaultLaunchScript;
|
||||
import org.springframework.boot.loader.tools.LaunchScript;
|
||||
import org.springframework.boot.loader.tools.Repackager;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
@@ -80,6 +82,10 @@ public class RepackageTask extends DefaultTask {
|
||||
this.classifier = classifier;
|
||||
}
|
||||
|
||||
void setOutputFile(File file) {
|
||||
this.outputFile = file;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
public void repackage() {
|
||||
Project project = getProject();
|
||||
@@ -170,7 +176,8 @@ public class RepackageTask extends DefaultTask {
|
||||
}
|
||||
repackager.setBackupSource(this.extension.isBackupSource());
|
||||
try {
|
||||
repackager.repackage(file, this.libraries);
|
||||
LaunchScript launchScript = getLaunchScript();
|
||||
repackager.repackage(file, this.libraries, launchScript);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException(ex.getMessage(), ex);
|
||||
@@ -201,6 +208,15 @@ public class RepackageTask extends DefaultTask {
|
||||
getLogger().info("Setting mainClass: " + mainClass);
|
||||
repackager.setMainClass(mainClass);
|
||||
}
|
||||
|
||||
private LaunchScript getLaunchScript() throws IOException {
|
||||
if (this.extension.isExecutable()) {
|
||||
return new DefaultLaunchScript(this.extension.getEmbeddedLaunchScript(),
|
||||
this.extension.getEmbeddedLaunchScriptProperties());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,10 +244,7 @@ public class RepackageTask extends DefaultTask {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setOutputFile(File file) {
|
||||
this.outputFile = file;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user