Skip to content

Commit

Permalink
Merge pull request #99 from humpfle/master
Browse files Browse the repository at this point in the history
Support update and execution of any executable jar
  • Loading branch information
Edvin Syse authored Feb 19, 2018
2 parents 98cc4f3 + cf05665 commit 3a04053
Showing 1 changed file with 29 additions and 6 deletions.
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 3a04053

Please sign in to comment.