Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support update and execution of any executable jar #99

Merged
merged 2 commits into from
Feb 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}