private ProcessDescription start()

in src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java [174:249]


    private ProcessDescription start(final File jar) throws Exception {
        final ProcessDescription cfg = new ProcessDescription(this.configuration.getId(), this.configuration.getFolder());

        final ProcessBuilder builder = new ProcessBuilder();
        final List<String> args = new ArrayList<String>();

        String javaHome = System.getenv("JAVA_HOME");
        String javaCmd = javaHome != null ? Paths.get(javaHome, "bin", "java").toString() : "java";

        args.add(javaCmd);
        add(args, this.configuration.getVmOpts());
        add(args, this.configuration.getVmDebugOpts(this.environment.getDebug()));

        args.add("-cp");
        args.add("bin");
        args.add(Main.class.getName());
        // first three arguments: jar, listener port, verbose
        args.add(jar.getPath());
        args.add(String.valueOf(cfg.getControlListener().getPort()));
        args.add("true");

        // from here on launchpad properties
        add(args, this.configuration.getOpts());

        final String contextPath = this.configuration.getContextPath();
        if ( contextPath != null && contextPath.length() > 0 && !contextPath.equals("/") ) {
            args.add("-r");
            args.add(contextPath);
        }

        if ( this.configuration.getPort() != null ) {
            args.add("-p");
            args.add(this.configuration.getPort());
        }

        if ( this.configuration.getControlPort() != null ) {
            args.add("-j");
            args.add(this.configuration.getControlPort());
        }
        if ( this.configuration.getRunmode() != null && this.configuration.getRunmode().length() > 0 ) {
            args.add("-Dsling.run.modes=" + this.configuration.getRunmode());
        }
        if ( !this.environment.isShutdownOnExit() ) {
            args.add("start");
        }

        builder.command(args.toArray(new String[args.size()]));
        builder.directory(this.configuration.getFolder());
        builder.redirectErrorStream(true);
        logger.info("Starting Launchpad " + this.configuration.getId() +  "...");
        String stdOutFile = this.configuration.getStdOutFile();
        if (StringUtils.isNotBlank(stdOutFile)) {
            File absoluteStdOutFile = new File(builder.directory(), stdOutFile);
            // make sure to create the parent directories (if they do not exist yet)
            absoluteStdOutFile.getParentFile().mkdirs();
            builder.redirectOutput(absoluteStdOutFile);
            logger.info("Redirecting stdout and stderr to " + absoluteStdOutFile);
        } else {
            builder.redirectOutput(Redirect.INHERIT);
        }

        logger.debug("Launchpad cmd: " + builder.command());
        logger.debug("Launchpad dir: " + builder.directory());

        try {
            cfg.setProcess(builder.start());
        } catch (final IOException e) {
            if (cfg.getProcess() != null) {
                cfg.getProcess().destroy();
                cfg.setProcess(null);
            }
            throw new Exception("Could not start the Launchpad", e);
        }

        return cfg;
    }