public static void main()

in hawtio-app/src/main/java/io/hawt/app/App.java [37:125]


    public static void main(String[] args) {

        Object val = System.getProperty("hawtio.authenticationEnabled");
        if (val == null) {
            System.setProperty("hawtio.authenticationEnabled", "false");
        }

        Main main = new Main();

        try {
            String virtualMachineClass = "com.sun.tools.attach.VirtualMachine";
            try {
                loadClass(virtualMachineClass, App.class.getClassLoader(), Thread.currentThread().getContextClassLoader());
            } catch (Exception e) {
                // lets try find the tools.jar instead
                Set<String> paths = new HashSet<>();
                String javaHome = System.getProperty("java.home", ".");
                addPath(paths, javaHome);

                // now lets try the JAVA_HOME environment variable just in case
                javaHome = System.getenv("JAVA_HOME");
                if (javaHome != null && javaHome.length() > 0) {
                    addPath(paths, javaHome);
                }

                boolean found = false;
                for (String path : paths) {
                    File file = new File(path, "lib/tools.jar");
                    if (file.exists()) {
                        found = true;
                        String url = file.toURI().toURL().toString();
                        main.setExtraClassPath(url);
                        break;
                    }
                }
                if (!found) {
                    System.err.println(String.format(
                        "Failed to load class %s and find tools.jar in directories %s. %s",
                        virtualMachineClass, paths, e));
                }
            }

            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            URL resource = classLoader.getResource(WAR_FILENAME);
            if (resource == null) {
                System.err.println(String.format("Could not find the %s on classpath!", WAR_FILENAME));
                System.exit(1);
            }
            File warFile = File.createTempFile("hawtio-", ".war");
            writeStreamTo(resource.openStream(), new FileOutputStream(warFile), 64 * KB);

            String warPath = warFile.getCanonicalPath();
            main.setWar(warPath);
        } catch (Exception e) {
            System.err.println("Failed to create hawtio: " + e.getMessage());
            e.printStackTrace();
            return;
        }

        if (!main.parseArguments(args) || main.isHelp()) {
            main.showOptions();
        } else {
            try {
                main.run();

                // should we open the url
                int port = main.getPort();
                String url = "http://localhost:" + port + main.getContextPath();
                // set what is the url
                System.setProperty("hawtio.url", url);

                String open = main.isOpenUrl() ? "true" : "false";
                // JVM system override the main option
                boolean openUrl = "true".equals(System.getProperty("hawtio.openUrl", open));
                if (openUrl && Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(new URI(url));
                    } catch (Exception e) {
                        System.err.println(String.format(
                            "Failed to open browser session, to access hawtio visit \"%s\"",
                            url));
                    }
                }
            } catch (Exception e) {
                System.err.println("Failed running hawtio: " + e.getMessage());
                e.printStackTrace();
            }
        }
    }