Package io.hawt.embedded

Examples of io.hawt.embedded.Main


        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 {
                Class<?> aClass = loadClass(virtualMachineClass, App.class.getClassLoader(), Thread.currentThread().getContextClassLoader());
                //System.out.println("Found " + aClass + " on the classpath!");
            } catch (Exception e) {
                // lets try find the tools.jar instead
                Set<String> paths = new HashSet<String>();
                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.out.println("Failed to load class " + virtualMachineClass
                            + " and find tools.jar in directories " + paths + ". " + e);
                }
            }

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

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

        if (!main.parseArguments(args) || main.isHelp()) {
            main.showOptions();
        } else {
            try {
                main.run();
                if (Desktop.isDesktopSupported()) {
                    int port = main.getPort();
                    String url = "http://localhost:" +  port + main.getContextPath();
                    try {
                        Desktop.getDesktop().browse(new URI(url));
                    } catch (Exception e) {
                        System.out.println("Failed to open browser session, to access hawtio visit \"" + url + "\"");
                    }
View Full Code Here

TOP

Related Classes of io.hawt.embedded.Main

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.