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:com.twosigma.beakerx.groovy.evaluator.GroovyClassLoaderFactory.java

public static BeakerXUrlClassLoader newParentClassLoader(Classpath classpath) {
    BeakerXUrlClassLoader loader = new BeakerXUrlClassLoader(ClassLoader.getSystemClassLoader());
    loader.addPathToJars(classpath.getPaths());
    return loader;
}

From source file:nl.ru.cmbi.vase.tools.util.ToolBox.java

static public List<String> getInsideContents(String fileName) {
    ClassLoader loader = ToolBox.class.getClassLoader();
    InputStream stream = loader.getResourceAsStream(fileName);

    if (stream == null) {
        loader = ClassLoader.getSystemClassLoader();
        stream = loader.getResourceAsStream(fileName);
    }/*from  w  w  w. java  2 s  . co  m*/
    // stream = loader.getResourceAsStream("spring.xml");
    StringBuffer contents = new StringBuffer();
    List<String> lines = new ArrayList<String>();
    BufferedReader input = null;
    try {
        input = new BufferedReader(new InputStreamReader(stream));
        String line = null; // not declared within while loop
        while ((line = input.readLine()) != null) {
            lines.add(line);
            contents.append(line);
            contents.append(System.getProperty("line.separator"));
        }
    } catch (Exception e) {
        LOG.fatal(e);
    } finally {
        try {
            if (input != null) {
                input.close();
            }
        } catch (Exception e) {
            LOG.warn(e);
        }
    }
    return lines;
}

From source file:org.jodconverter.office.OnlineOfficeManagerPoolEntry.java

private static ClassLoader getDefaultClassLoader() {

    ClassLoader cl = null;//from w  w w  . j av a 2 s  .co m
    try {
        cl = Thread.currentThread().getContextClassLoader();
    } catch (Throwable ex) {
        // Cannot access thread context ClassLoader - falling back...
    }
    if (cl == null) {
        // No thread context class loader -> use class loader of this class.
        cl = OnlineOfficeManagerPoolEntry.class.getClassLoader();
        if (cl == null) {
            // getClassLoader() returning null indicates the bootstrap ClassLoader
            try {
                cl = ClassLoader.getSystemClassLoader();
            } catch (Throwable ex) { // NOSONAR
                // Cannot access system ClassLoader - oh well, maybe the caller can live with null...
            }
        }
    }
    return cl;
}

From source file:cosmos.results.integration.CosmosIntegrationSetup.java

@BeforeClass
public static void initializeJaxb() throws Exception {
    if (null == context) {
        context = JAXBContext.newInstance("org.mediawiki.xml.export_0", ClassLoader.getSystemClassLoader());
    }//from ww  w .  ja va2s .c  om
}

From source file:org.broadleafcommerce.common.extensibility.InstrumentationRuntimeFactory.java

/**
 * This method returns the Instrumentation object provided by the JVM. If the Instrumentation object is null,
 * it does its best to add an instrumentation agent to the JVM and then the instrumentation object.
 * @return Instrumentation/*from  w w  w. j  a  v a  2s. c o  m*/
 */
public static synchronized Instrumentation getInstrumentation() {
    if (inst != null) {
        return inst;
    }

    if (System.getProperty("java.vendor").toUpperCase().contains("IBM")) {
        isIBM = true;
    }

    AccessController.doPrivileged(new PrivilegedAction<Object>() {
        public Object run() {
            try {
                if (!InstrumentationRuntimeFactory.class.getClassLoader()
                        .equals(ClassLoader.getSystemClassLoader())) {
                    return null;
                }
            } catch (Throwable t) {
                return null;
            }
            File toolsJar = null;
            // When running on IBM, the attach api classes are packaged in vm.jar which is a part
            // of the default vm classpath.
            if (!isIBM) {
                // If we can't find the tools.jar and we're not on IBM we can't load the agent.
                toolsJar = findToolsJar();
                if (toolsJar == null) {
                    return null;
                }
            }

            Class<?> vmClass = loadVMClass(toolsJar);
            if (vmClass == null) {
                return null;
            }
            String agentPath = getAgentJar();
            if (agentPath == null) {
                return null;
            }
            loadAgent(agentPath, vmClass);
            return null;
        }
    });

    return inst;
}

From source file:org.apache.accumulo.start.classloader.vfs.AccumuloReloadingVFSClassLoaderTest.java

@Test
public void testConstructor() throws Exception {
    FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString());
    FileObject[] dirContents = testDir.getChildren();

    AccumuloReloadingVFSClassLoader arvcl = new AccumuloReloadingVFSClassLoader(folderPath, vfs,
            new ReloadingClassLoader() {
                @Override//from w w w .ja  va2s. c o  m
                public ClassLoader getClassLoader() {
                    return ClassLoader.getSystemClassLoader();
                }
            }, true);

    VFSClassLoader cl = (VFSClassLoader) arvcl.getClassLoader();

    FileObject[] files = cl.getFileObjects();
    Assert.assertArrayEquals(createFileSystems(dirContents), files);

    arvcl.close();
}

From source file:blue.lapis.pore.converter.type.TypeConverterTest.java

@Test
public void load() throws ClassNotFoundException {
    Class.forName(CONVERTER_PREFIX + converter, true, ClassLoader.getSystemClassLoader());
}

From source file:com.app.server.XMLDeploymentScanner.java

public void init(Vector serviceList, ServerConfig serverConfig, MBeanServer mbeanServer) {
    this.serviceList = serviceList;
    this.serverConfig = serverConfig;
    this.mbeanServer = mbeanServer;
    this.userLibDir = serverConfig.getServiceslibdirectory();
    File userLibJars = new File(userLibDir);
    CopyOnWriteArrayList<String> jarList = new CopyOnWriteArrayList();
    getUsersJars(userLibJars, jarList);//www  . j a v  a 2s . c o  m
    URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    userLibJarLoader = new WebClassLoader(loader.getURLs());
    for (String jarFilePath : jarList) {
        try {
            userLibJarLoader.addURL(new URL("file:/" + jarFilePath.replace("\\", "/")));
        } catch (Exception e) {
            log.error("Error in url " + "file:/" + jarFilePath.replace("\\", "/"), e);
            //e2.printStackTrace();            
        }
    }

    DigesterLoader xmlDigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

        protected void loadRules() {

            try {
                loadXMLRules(new InputSource(new FileInputStream("./config/datasource-rules.xml")));
            } catch (Exception e) {
                log.error("Error in loading config rules ./config/datasource-rules.xml", e);
                //e.printStackTrace();
            }

        }
    });
    xmlDigester = xmlDigesterLoader.newDigester();
    try {
        ic = new InitialContext();
        ic.createSubcontext("java:");
    } catch (Exception e) {
        log.error("Error in creating subcontext", e);
    }
    log.info("initialized");
    // TODO Auto-generated constructor stub
}

From source file:org.programmatori.domotica.own.server.engine.EngineManagerImpl.java

public EngineManagerImpl() {
    log.trace("Start Create Istance");
    setName("SCS Engine");
    //setDaemon(true);
    Config.getInstance().addThread(this);

    //Load Engine
    try {/*from w w  w .  ja  v a 2  s.  com*/
        String busName = Config.getInstance().getBus();
        log.debug("Engine Class Name: " + busName);

        Class<?> c = ClassLoader.getSystemClassLoader().loadClass(busName);
        engine = (Engine) c.newInstance();
        //engine.addEventListener(this);
    } catch (NoClassDefFoundError e) {
        if (e.getMessage().indexOf("SerialPortEventListener") > -1) {
            log.error("You must install RXTX library (http://rxtx.qbang.org/)");
        } else {
            throw e;
        }
        System.exit(-1);
    } catch (Exception e) {
        log.error(LogUtility.getErrorTrace(e));
        System.exit(-1);
    }

    msgSended = new ListenerPriorityBlockingQueue<Command>();
    msgSended.addListener(this);
    changeQueue = false;

    //monitors = new ArrayList<Monitor>();
    sender = new MsgSender(engine, msgSended);
    sender.start();
    receiver = new MsgReceiver(engine, msgSended);
    msgSended.addListener(receiver);
    receiver.start();
    sendTimeout = Config.getInstance().getSendTimeout();

    // load Module
    loadPlugIn();

    log.trace("End Create Istance");
}

From source file:eu.stratosphere.nephele.io.compression.CompressionLoader.java

/**
 * Returns the path to the native libraries or <code>null</code> if an error occurred.
 * //from  w  w  w . j  a v  a  2 s  .  c  o  m
 * @param libraryClass
 *        the name of this compression library's wrapper class including full package name
 * @return the path to the native libraries or <code>null</code> if an error occurred
 */
private static String getNativeLibraryPath(final String libraryClass) {

    final ClassLoader cl = ClassLoader.getSystemClassLoader();
    if (cl == null) {
        LOG.error("Cannot find system class loader");
        return null;
    }

    final String classLocation = libraryClass.replace('.', '/') + ".class";
    if (LOG.isDebugEnabled()) {
        LOG.debug("Class location is " + classLocation);
    }

    final URL location = cl.getResource(classLocation);
    if (location == null) {
        LOG.error("Cannot determine location of CompressionLoader class");
        return null;
    }

    final String locationString = location.toString();
    if (locationString.contains(".jar!")) { // Class if inside of a deployed jar file

        // Create and return path to native library cache
        final String pathName = GlobalConfiguration
                .getString(ConfigConstants.TASK_MANAGER_TMP_DIR_KEY,
                        ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH)
                .split(File.pathSeparator)[0] + File.separator + NATIVELIBRARYCACHENAME;

        final File path = new File(pathName);
        if (!path.exists()) {
            if (!path.mkdir()) {
                LOG.error("Cannot create directory for native library cache.");
                return null;
            }
        }

        return pathName;

    } else {

        String result = "";

        int pos = locationString.indexOf(classLocation);
        if (pos < 0) {
            LOG.error("Cannot find extract native path from class location");
            return null;
        }

        result = locationString.substring(0, pos) + "META-INF/lib";

        // Strip the file:/ scheme, it confuses the class loader
        if (result.startsWith("file:")) {
            result = result.substring(5);
        }

        return result;
    }
}