Example usage for org.apache.commons.lang SystemUtils JAVA_CLASS_PATH

List of usage examples for org.apache.commons.lang SystemUtils JAVA_CLASS_PATH

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils JAVA_CLASS_PATH.

Prototype

String JAVA_CLASS_PATH

To view the source code for org.apache.commons.lang SystemUtils JAVA_CLASS_PATH.

Click Source Link

Document

The java.class.path System Property.

Usage

From source file:com.yahoo.flowetl.commons.runner.Main.java

/**
 * Gets some useful runtime info as a map of names -> info.
 *///from www .ja  v  a2s . c  om
private static Map<String, Object> getRuntimeInfo() {
    Map<String, Object> sysInfo = new TreeMap<String, Object>();
    StringBuilder jvminfo = new StringBuilder();
    jvminfo.append("Vendor: ");
    jvminfo.append(SystemUtils.JAVA_VENDOR);
    jvminfo.append(", Version: ");
    jvminfo.append(SystemUtils.JAVA_VERSION + " - " + SystemUtils.JAVA_VM_INFO);
    jvminfo.append(", OS: ");
    jvminfo.append(SystemUtils.OS_NAME + " (" + SystemUtils.OS_VERSION + " : " + SystemUtils.OS_ARCH + ")");
    sysInfo.put(WordUtils.capitalizeFully("jvm"), jvminfo.toString());
    sysInfo.put(WordUtils.capitalizeFully("default charset encoding"), DEF_CHAR_SET.name());
    String netAdd = NetUtils.getLocalAddress();
    if (StringUtils.isEmpty(netAdd)) {
        netAdd = "????";
    }
    String localName = NetUtils.getLocalHostName();
    if (StringUtils.isEmpty(localName)) {
        localName = "????";
    }
    sysInfo.put(WordUtils.capitalizeFully("network"), localName + " at ip address " + netAdd);
    String cPath = SystemUtils.JAVA_CLASS_PATH;
    String linesep = StringEscapeUtils.escapeJava(SystemUtils.LINE_SEPARATOR);
    sysInfo.put(WordUtils.capitalizeFully("classpath"), cPath);
    sysInfo.put(WordUtils.capitalizeFully("jvm home"), SystemUtils.JAVA_HOME);
    sysInfo.put(WordUtils.capitalizeFully("jvm tmpdir"), SystemUtils.JAVA_IO_TMPDIR);
    sysInfo.put(WordUtils.capitalizeFully("jvm libpath"), SystemUtils.JAVA_LIBRARY_PATH);
    sysInfo.put(WordUtils.capitalizeFully("line separator"), linesep);
    sysInfo.put(WordUtils.capitalizeFully("path separator"),
            StringEscapeUtils.escapeJava(SystemUtils.PATH_SEPARATOR));
    sysInfo.put(WordUtils.capitalizeFully("user timezone"), SystemUtils.USER_TIMEZONE);
    sysInfo.put(WordUtils.capitalizeFully("user home"), SystemUtils.USER_HOME);
    sysInfo.put(WordUtils.capitalizeFully("user language"), SystemUtils.USER_LANGUAGE);
    sysInfo.put(WordUtils.capitalizeFully("user name"), SystemUtils.USER_NAME);
    return sysInfo;
}

From source file:org.apache.cocoon.bean.CocoonWrapper.java

/**
 * This builds the important ClassPath used by this class.  It
 * does so in a neutral way.//from  w  ww.  j  a  va  2 s  .co m
 * It iterates in alphabetical order through every file in the
 * lib directory and adds it to the classpath.
 *
 * Also, we add the files to the ClassLoader for the Cocoon system.
 * In order to protect ourselves from skitzofrantic classloaders,
 * we need to work with a known one.
 *
 * @param context  The context path
 * @return a <code>String</code> value
 */
protected String getClassPath(final String context) {
    StringBuffer buildClassPath = new StringBuffer();

    String classDir = context + "/WEB-INF/classes";
    buildClassPath.append(classDir);

    File root = new File(context + "/WEB-INF/lib");
    if (root.isDirectory()) {
        File[] libraries = root.listFiles();
        Arrays.sort(libraries);
        for (int i = 0; i < libraries.length; i++) {
            if (libraries[i].getAbsolutePath().endsWith(".jar")) {
                buildClassPath.append(File.pathSeparatorChar).append(IOUtils.getFullFilename(libraries[i]));
            }
        }
    }

    buildClassPath.append(File.pathSeparatorChar).append(SystemUtils.JAVA_CLASS_PATH);

    // Extra class path is necessary for non-classloader-aware java compilers to compile XSPs
    //        buildClassPath.append(File.pathSeparatorChar)
    //                      .append(getExtraClassPath(context));

    if (log.isDebugEnabled()) {
        log.debug("Context classpath: " + buildClassPath);
    }
    return buildClassPath.toString();
}

From source file:org.apache.cocoon.components.language.programming.java.JavaLanguage.java

public void initialize() throws Exception {

    // Initialize the classpath
    String systemBootClasspath = System.getProperty("sun.boot.class.path");
    String systemClasspath = SystemUtils.JAVA_CLASS_PATH;
    String systemExtDirs = SystemUtils.JAVA_EXT_DIRS;
    String systemExtClasspath = null;

    try {//from  ww w  .  j a v a 2 s.  c o  m
        systemExtClasspath = expandDirs(systemExtDirs);
    } catch (Exception e) {
        getLogger().warn("Could not expand Directory:" + systemExtDirs, e);
    }

    this.classpath = ((super.classpath != null) ? File.pathSeparator + super.classpath : "")
            + ((systemBootClasspath != null) ? File.pathSeparator + systemBootClasspath : "")
            + ((systemClasspath != null) ? File.pathSeparator + systemClasspath : "")
            + ((systemExtClasspath != null) ? File.pathSeparator + systemExtClasspath : "");
}

From source file:org.apache.cocoon.generation.StatusGenerator.java

private void genVMStatus() throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    startGroup("VM");

    // BEGIN ClassPath
    String classpath = SystemUtils.JAVA_CLASS_PATH;
    if (classpath != null) {
        List paths = new ArrayList();
        StringTokenizer tokenizer = new StringTokenizer(classpath, SystemUtils.PATH_SEPARATOR);
        while (tokenizer.hasMoreTokens()) {
            paths.add(tokenizer.nextToken());
        }/*  ww w .  j a  v a2s. c  o  m*/
        addMultilineValue("classpath", paths);
    }
    // END ClassPath

    // BEGIN CONTEXT CLASSPATH
    String contextClassPath = null;
    try {
        contextClassPath = (String) this.context.get(Constants.CONTEXT_CLASSPATH);
    } catch (ContextException e) {
        // we ignore this
    }
    if (contextClassPath != null) {
        List paths = new ArrayList();
        StringTokenizer tokenizer = new StringTokenizer(contextClassPath, File.pathSeparator);
        while (tokenizer.hasMoreTokens()) {
            paths.add(tokenizer.nextToken());
        }
        addMultilineValue("context-classpath", paths);
    }
    // END CONTEXT CLASSPATH

    // BEGIN Memory status
    startGroup("Memory");
    final long totalMemory = Runtime.getRuntime().totalMemory();
    final long freeMemory = Runtime.getRuntime().freeMemory();
    addValue("total", String.valueOf(totalMemory));
    addValue("used", String.valueOf(totalMemory - freeMemory));
    addValue("free", String.valueOf(freeMemory));
    endGroup();
    // END Memory status

    // BEGIN JRE
    startGroup("JRE");
    addValue("version", SystemUtils.JAVA_VERSION);
    atts.clear();
    // qName = prefix + ':' + localName
    atts.addAttribute(XLINK_NS, "type", XLINK_PREFIX + ":type", "CDATA", "simple");
    atts.addAttribute(XLINK_NS, "href", XLINK_PREFIX + ":href", "CDATA", SystemUtils.JAVA_VENDOR_URL);
    addValue("java-vendor", SystemUtils.JAVA_VENDOR, atts);
    endGroup();
    // END JRE

    // BEGIN Operating system
    startGroup("Operating System");
    addValue("name", SystemUtils.OS_NAME);
    addValue("architecture", SystemUtils.OS_ARCH);
    addValue("version", SystemUtils.OS_VERSION);
    endGroup();
    // END operating system

    // BEGIN Cache
    if (this.storeJanitor != null) {
        startGroup("Store Janitor");

        // For each element in StoreJanitor
        Iterator i = this.storeJanitor.iterator();
        while (i.hasNext()) {
            Store store = (Store) i.next();
            startGroup(
                    store.getClass().getName() + " (hash = 0x" + Integer.toHexString(store.hashCode()) + ")");
            int size = 0;
            int empty = 0;
            atts.clear();
            atts.addAttribute(NAMESPACE, "name", "name", "CDATA", "cached");
            super.contentHandler.startElement(NAMESPACE, "value", "value", atts);

            atts.clear();
            Enumeration e = store.keys();
            while (e.hasMoreElements()) {
                size++;
                Object key = e.nextElement();
                Object val = store.get(key);
                String line;
                if (val == null) {
                    empty++;
                } else {
                    line = key + " (class: " + val.getClass().getName() + ")";
                    super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
                    super.contentHandler.characters(line.toCharArray(), 0, line.length());
                    super.contentHandler.endElement(NAMESPACE, "line", "line");
                }
            }
            if (size == 0) {
                super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
                String value = "[empty]";
                super.contentHandler.characters(value.toCharArray(), 0, value.length());
                super.contentHandler.endElement(NAMESPACE, "line", "line");
            }
            super.contentHandler.endElement(NAMESPACE, "value", "value");

            addValue("size", String.valueOf(size) + " items in cache (" + empty + " are empty)");
            endGroup();
        }
        endGroup();
    }

    if (this.storePersistent != null) {
        startGroup(storePersistent.getClass().getName() + " (hash = 0x"
                + Integer.toHexString(storePersistent.hashCode()) + ")");
        int size = 0;
        int empty = 0;
        atts.clear();
        atts.addAttribute(NAMESPACE, "name", "name", "CDATA", "cached");
        super.contentHandler.startElement(NAMESPACE, "value", "value", atts);

        atts.clear();
        Enumeration e = this.storePersistent.keys();
        while (e.hasMoreElements()) {
            size++;
            Object key = e.nextElement();
            Object val = storePersistent.get(key);
            String line;
            if (val == null) {
                empty++;
            } else {
                line = key + " (class: " + val.getClass().getName() + ")";
                super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
                super.contentHandler.characters(line.toCharArray(), 0, line.length());
                super.contentHandler.endElement(NAMESPACE, "line", "line");
            }
        }
        if (size == 0) {
            super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
            String value = "[empty]";
            super.contentHandler.characters(value.toCharArray(), 0, value.length());
            super.contentHandler.endElement(NAMESPACE, "line", "line");
        }
        super.contentHandler.endElement(NAMESPACE, "value", "value");

        addValue("size", size + " items in cache (" + empty + " are empty)");
        endGroup();
    }
    // END Cache

    endGroup();
}

From source file:org.apache.cocoon.portlet.CocoonPortlet.java

/**
 * This builds the important ClassPath used by this Portlet.  It
 * does so in a Portlet Engine neutral way.  It uses the
 * <code>PortletContext</code>'s <code>getRealPath</code> method
 * to get the Portlet identified classes and lib directories.
 * It iterates in alphabetical order through every file in the
 * lib directory and adds it to the classpath.
 *
 * Also, we add the files to the ClassLoader for the Cocoon system.
 * In order to protect ourselves from skitzofrantic classloaders,
 * we need to work with a known one.//w  w  w  .  j a v a 2 s. c  o  m
 *
 * We need to get this to work properly when Cocoon is in a war.
 *
 * @throws PortletException
 */
protected String getClassPath() throws PortletException {
    StringBuffer buildClassPath = new StringBuffer();

    File root = null;
    if (portletContextPath != null) {
        // Old method.  There *MUST* be a better method than this...

        String classDir = this.portletContext.getRealPath("/WEB-INF/classes");
        String libDir = this.portletContext.getRealPath("/WEB-INF/lib");

        if (libDir != null) {
            root = new File(libDir);
        }

        if (classDir != null) {
            buildClassPath.append(classDir);

            addClassLoaderDirectory(classDir);
        }
    } else {
        // New(ish) method for war'd deployments
        URL classDirURL = null;
        URL libDirURL = null;

        try {
            classDirURL = this.portletContext.getResource("/WEB-INF/classes");
        } catch (MalformedURLException me) {
            if (getLogger().isWarnEnabled()) {
                this.getLogger().warn("Unable to add WEB-INF/classes to the classpath", me);
            }
        }

        try {
            libDirURL = this.portletContext.getResource("/WEB-INF/lib");
        } catch (MalformedURLException me) {
            if (getLogger().isWarnEnabled()) {
                this.getLogger().warn("Unable to add WEB-INF/lib to the classpath", me);
            }
        }

        if (libDirURL != null && libDirURL.toExternalForm().startsWith("file:")) {
            root = new File(libDirURL.toExternalForm().substring("file:".length()));
        }

        if (classDirURL != null) {
            buildClassPath.append(classDirURL.toExternalForm());

            addClassLoaderURL(classDirURL);
        }
    }

    // Unable to find lib directory. Going the hard way.
    if (root == null) {
        root = extractLibraries();
    }

    if (root != null && root.isDirectory()) {
        File[] libraries = root.listFiles();
        Arrays.sort(libraries);
        for (int i = 0; i < libraries.length; i++) {
            String fullName = IOUtils.getFullFilename(libraries[i]);
            buildClassPath.append(File.pathSeparatorChar).append(fullName);

            addClassLoaderDirectory(fullName);
        }
    }

    buildClassPath.append(File.pathSeparatorChar).append(SystemUtils.JAVA_CLASS_PATH);

    buildClassPath.append(File.pathSeparatorChar).append(getExtraClassPath());
    return buildClassPath.toString();
}

From source file:org.apache.cocoon.servlet.CocoonServlet.java

/**
 * This builds the important ClassPath used by this Servlet.  It
 * does so in a Servlet Engine neutral way.  It uses the
 * <code>ServletContext</code>'s <code>getRealPath</code> method
 * to get the Servlet 2.2 identified classes and lib directories.
 * It iterates in alphabetical order through every file in the
 * lib directory and adds it to the classpath.
 *
 * Also, we add the files to the ClassLoader for the Cocoon system.
 * In order to protect ourselves from skitzofrantic classloaders,
 * we need to work with a known one.//from ww  w  . j  a v a  2s.  c  o m
 *
 * We need to get this to work properly when Cocoon is in a war.
 *
 * @throws ServletException
 */
protected String getClassPath() throws ServletException {
    StringBuffer buildClassPath = new StringBuffer();

    File root = null;
    if (servletContextPath != null) {
        // Old method.  There *MUST* be a better method than this...

        String classDir = this.servletContext.getRealPath("/WEB-INF/classes");
        String libDir = this.servletContext.getRealPath("/WEB-INF/lib");

        if (libDir != null) {
            root = new File(libDir);
        }

        if (classDir != null) {
            buildClassPath.append(classDir);

            addClassLoaderDirectory(classDir);
        }
    } else {
        // New(ish) method for war'd deployments
        URL classDirURL = null;
        URL libDirURL = null;

        try {
            classDirURL = this.servletContext.getResource("/WEB-INF/classes");
        } catch (MalformedURLException me) {
            if (getLogger().isWarnEnabled()) {
                this.getLogger().warn("Unable to add WEB-INF/classes to the classpath", me);
            }
        }

        try {
            libDirURL = this.servletContext.getResource("/WEB-INF/lib");
        } catch (MalformedURLException me) {
            if (getLogger().isWarnEnabled()) {
                this.getLogger().warn("Unable to add WEB-INF/lib to the classpath", me);
            }
        }

        if (libDirURL != null && libDirURL.toExternalForm().startsWith("file:")) {
            root = new File(libDirURL.toExternalForm().substring("file:".length()));
        }

        if (classDirURL != null) {
            buildClassPath.append(classDirURL.toExternalForm());

            addClassLoaderURL(classDirURL);
        }
    }

    // Unable to find lib directory. Going the hard way.
    if (root == null) {
        root = extractLibraries();
    }

    if (root != null && root.isDirectory()) {
        File[] libraries = root.listFiles();
        Arrays.sort(libraries);
        for (int i = 0; i < libraries.length; i++) {
            String fullName = IOUtils.getFullFilename(libraries[i]);
            buildClassPath.append(File.pathSeparatorChar).append(fullName);

            addClassLoaderDirectory(fullName);
        }
    }

    buildClassPath.append(File.pathSeparatorChar).append(SystemUtils.JAVA_CLASS_PATH);

    buildClassPath.append(File.pathSeparatorChar).append(getExtraClassPath());
    return buildClassPath.toString();
}

From source file:org.apache.ctakes.jdl.common.FileUtil.java

/**
 * @return the javaClassPaths
 */
public static String[] getJavaClassPaths() {
    return SystemUtils.JAVA_CLASS_PATH.split(SystemUtils.PATH_SEPARATOR);
}

From source file:org.zeroturnaround.exec.test.shutdown.ProcessExecutorShutdownHookTest.java

private void testDestroyOnExit(Class<?> starter, boolean fileIsAlwaysCreated) throws Exception {
    File file = WriterLoop.getFile();
    if (file.exists())
        FileUtils.forceDelete(file);/*from  ww  w. j  av  a  2 s  .c  o m*/
    new ProcessExecutor("java", "-cp", SystemUtils.JAVA_CLASS_PATH, starter.getName()).redirectOutputAsInfo()
            .execute();
    // After WriterLoopStarter has finished we expect that WriterLoop is also finished - no-one is updating the file
    if (fileIsAlwaysCreated || file.exists()) {
        checkFileStaysTheSame(file);
        FileUtils.forceDelete(file);
    }
}