Example usage for java.lang ClassLoader getSystemClassLoader

List of usage examples for java.lang ClassLoader getSystemClassLoader

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemClassLoader.

Prototype

@CallerSensitive
public static ClassLoader getSystemClassLoader() 

Source Link

Document

Returns the system class loader.

Usage

From source file:net.volcore.wtvmaster.Main.java

/** should be called once in the beginning, sets up all the required logging. */
protected static void initializeLogging() {
    // Initialize logging
    String name = "wtvmaster-log4j.properties";
    URL log4jfile = ClassLoader.getSystemClassLoader().getResource(name);
    if (log4jfile == null)
        throw new Error("Could not find " + name + "!");
    org.apache.log4j.PropertyConfigurator.configure(log4jfile);
}

From source file:Main.java

private static ClassLoader getClassLoader(ClassLoader classLoader) {
    if (classLoader == null) {
        return ClassLoader.getSystemClassLoader();
    }// ww  w. j  a v a2s  .  co  m
    return classLoader;
}

From source file:Main.java

private static void addtoClassLoader(URL url) throws IOException, NoSuchMethodException, SecurityException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Class<URLClassLoader> sysclass = URLClassLoader.class;
    Method method = sysclass.getDeclaredMethod("addURL", parameters);
    method.setAccessible(true);// w w w. j  a v a  2s.  c  o m
    method.invoke(sysloader, new Object[] { url });
}

From source file:com.elemenopy.backupcopy.config.BackupConfig.java

public static BackupConfig loadFromClasspath(String fname) {
    InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(fname);
    if (is == null)
        return null;
    return loadConfigFile(is);
}

From source file:Main.java

private static void loadProviderIfNecessary(String providerClassName) {
    if (providerClassName == null) {
        return;//from   ww  w .j  a  v  a2s  .  c om
    }

    final Class<?> klass;
    try {
        final ClassLoader sysLoader = ClassLoader.getSystemClassLoader();
        if (sysLoader != null) {
            klass = sysLoader.loadClass(providerClassName);
        } else {
            klass = Class.forName(providerClassName);
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        System.exit(1);
        return;
    }

    Constructor<?> constructor = null;
    for (Constructor<?> c : klass.getConstructors()) {
        if (c.getParameterTypes().length == 0) {
            constructor = c;
            break;
        }
    }
    if (constructor == null) {
        System.err.println("No zero-arg constructor found for " + providerClassName);
        System.exit(1);
        return;
    }

    final Object o;
    try {
        o = constructor.newInstance();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
        return;
    }
    if (!(o instanceof Provider)) {
        System.err.println("Not a Provider class: " + providerClassName);
        System.exit(1);
    }

    Security.insertProviderAt((Provider) o, 1);
}

From source file:Main.java

public static InputStream getResourceAsStream(String name, Class clazz) {
    ClassLoader loader;//from ww  w . jav  a2  s .  c  om
    InputStream retval = null;

    // https://issues.jboss.org/browse/JGRP-1762: load the classloader from the defining class first
    if (clazz != null) {
        try {
            loader = clazz.getClassLoader();
            if (loader != null) {
                retval = loader.getResourceAsStream(name);
                if (retval != null)
                    return retval;
            }
        } catch (Throwable t) {
        }
    }

    try {
        loader = Thread.currentThread().getContextClassLoader();
        if (loader != null) {
            retval = loader.getResourceAsStream(name);
            if (retval != null)
                return retval;
        }
    } catch (Throwable t) {
    }

    try {
        loader = ClassLoader.getSystemClassLoader();
        if (loader != null) {
            return loader.getResourceAsStream(name);
        }
    } catch (Throwable t) {
    }

    return retval;
}

From source file:de.marza.firstspirit.modules.logging.fsm.FsmIT.java

/**
 * Sets up before./*from   w w  w. j a  va  2  s. c o  m*/
 *
 * @throws Exception the exception
 */
@BeforeClass
public static void setUpBefore() throws Exception {
    pomProperties = new Properties();
    final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    final InputStream inputStream = systemClassLoader.getResourceAsStream("moduleTest.properties");
    pomProperties.load(inputStream);
}

From source file:net.gazeplay.commons.utils.games.Utils.java

public static MenuBar buildLicence() {
    ClassLoader classLoader = ClassLoader.getSystemClassLoader();
    String licenseFileAsString = loadLicenseFileAsString(classLoader);

    MenuItem licenseMenuItem = new MenuItem(licenseFileAsString);

    Menu menu = new Menu("GazePlay");
    menu.getItems().add(licenseMenuItem);

    MenuBar menuBar = new MenuBar();
    menuBar.getMenus().addAll(menu);/*w  w  w . ja v a 2s.  com*/
    menuBar.setPrefHeight(40);
    menuBar.setPrefWidth(80);

    return menuBar;
}

From source file:Main.java

private static URL getRootUrlForClass(Class<?> cls) {
    ClassLoader classLoader = cls.getClassLoader();
    String resource = cls.getName().replace('.', '/') + ".class";
    if (classLoader == null) {
        // A null class loader means the bootstrap class loader. In this case we use the
        // system class loader. This is safe since we can assume that the system class
        // loader uses parent first as delegation policy.
        classLoader = ClassLoader.getSystemClassLoader();
    }/*w  w  w. j  a  v a2  s .  c  o  m*/
    URL url = classLoader.getResource(resource);
    if (url == null) {
        return null;
    }
    String file = url.getFile();
    if (file.endsWith(resource)) {
        try {
            return new URL(url.getProtocol(), url.getHost(), url.getPort(),
                    file.substring(0, file.length() - resource.length()));
        } catch (MalformedURLException ex) {
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.apache.storm.debug.DebugHelper.java

public static URL[] getClassPaths() {
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    return ((URLClassLoader) cl).getURLs();
}