Skip to content

Commit

Permalink
Support update/execution of any (spring boot) executable jar
Browse files Browse the repository at this point in the history
  • Loading branch information
humpfle committed Feb 17, 2018
1 parent 8c8dfa2 commit cf05665
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 113 deletions.
107 changes: 0 additions & 107 deletions src/main/java/fxlauncher/JFXPanelSwingLauncher.java

This file was deleted.

35 changes: 29 additions & 6 deletions src/main/java/fxlauncher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.*;
import java.net.URI;
import java.nio.file.Path;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -46,7 +47,9 @@ protected void createApplication(Class<Application> appClass) {
PlatformImpl.runAndWait(() ->
{
try {
app = appClass.newInstance();
if (appClass.isAssignableFrom(Application.class)){
app = appClass.newInstance();
}
} catch (Throwable t) {
reportError("Error creating app class", t);
}
Expand Down Expand Up @@ -157,11 +160,9 @@ public void start(Stage primaryStage) throws Exception {

private void launchAppFromManifest(boolean showWhatsnew) throws Exception {
superLauncher.setPhase("Application Environment Prepare");
ParametersImpl.registerParameters(app, new LauncherParams(getParameters(), superLauncher.getManifest()));
PlatformImpl.setApplicationName(app.getClass());
superLauncher.setPhase("Application Init");

try {
app.init();
initApplication();
} catch (Throwable ex) {
superLauncher.reportError("Error during app init", ex);
}
Expand All @@ -184,7 +185,7 @@ private void launchAppFromManifest(boolean showWhatsnew) throws Exception {
stage.close();
}

app.start(primaryStage);
startApplication();
} catch (Throwable ex) {
superLauncher.reportError("Failed to start application", ex);
}
Expand Down Expand Up @@ -220,4 +221,26 @@ public void stop() throws Exception {
if (app != null)
app.stop();
}

private void initApplication() throws Exception {
if (app != null){
app.init();
}
}

private void startApplication() throws Exception {
if (app != null){
ParametersImpl.registerParameters(app, new LauncherParams(getParameters(), superLauncher.getManifest()));
PlatformImpl.setApplicationName(app.getClass());
superLauncher.setPhase("Application Init");
app.start(primaryStage);
} else {
// Start any executable jar (i.E. Spring Boot);
List<LibraryFile> files = superLauncher.getManifest().files;
String cacheDir = superLauncher.getManifest().cacheDir;
String command = String.format("java -jar %s/%s", cacheDir, files.get(0).file);
log.info(String.format("Execute command '%s'",command));
Runtime.getRuntime().exec(command);
}
}
}

0 comments on commit cf05665

Please sign in to comment.