List of usage examples for java.lang ClassLoader getSystemClassLoader
@CallerSensitive public static ClassLoader getSystemClassLoader()
From source file:com.galeoconsulting.leonardinius.jruby.JRubyRegistrarImpl.java
private ClassLoader getClassLoader() { if (chainedClassLoader == null) { synchronized (lock) { if (chainedClassLoader == null) { chainedClassLoader = this.scriptService.getClassLoader(getClass().getClassLoader(), JRubyEngineFactory.class.getClassLoader(), UserManager.class.getClassLoader(), ClassLoader.getSystemClassLoader()); }/* w ww .j a v a 2 s.c o m*/ } } return chainedClassLoader; }
From source file:org.java.plugin.standard.StandardObjectFactory.java
protected Object createClassInstance(final String className) throws InstantiationException, IllegalAccessException, ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { try {//from w w w .j a va 2 s . c o m return cl.loadClass(className).newInstance(); } catch (ClassNotFoundException cnfe) { // ignore } } cl = getClass().getClassLoader(); if (cl != null) { try { return cl.loadClass(className).newInstance(); } catch (ClassNotFoundException cnfe) { // ignore } } return ClassLoader.getSystemClassLoader().loadClass(className).newInstance(); }
From source file:org.apache.xmlgraphics.util.ClasspathResource.java
private Set getClassLoadersForResources() { Set v = new HashSet(); try {/*from w w w .ja v a 2s . com*/ ClassLoader l = ClassLoader.getSystemClassLoader(); if (l != null) { v.add(l); } } catch (SecurityException e) { // Ignore } try { ClassLoader l = Thread.currentThread().getContextClassLoader(); if (l != null) { v.add(l); } } catch (SecurityException e) { // Ignore } try { ClassLoader l = ClasspathResource.class.getClassLoader(); if (l != null) { v.add(l); } } catch (SecurityException e) { // Ignore } return v; }
From source file:org.apache.ambari.server.security.CertGenerationTest.java
@BeforeClass public static void setUpBeforeClass() throws IOException { injector = Guice.createInjector(new SecurityModule()); certMan = injector.getInstance(CertificateManager.class); //Test using actual ca.config. try {// w ww. j av a2 s . c o m File caConfig = new File("conf/unix/ca.config"); if (System.getProperty("os.name").contains("Windows")) { caConfig = new File(new File(ClassLoader.getSystemClassLoader().getResource("").getPath()) .getParentFile().getParentFile(), "conf\\windows\\ca.config"); } File caConfigTest = new File(temp.getRoot().getAbsolutePath(), "ca.config"); File newCertsDir = new File(temp.getRoot().getAbsolutePath(), "newcerts"); newCertsDir.mkdirs(); File indexTxt = new File(temp.getRoot().getAbsolutePath(), "index.txt"); indexTxt.createNewFile(); String content = IOUtils.toString(new FileInputStream(caConfig)); if (System.getProperty("os.name").contains("Windows")) { content = content.replace("keystore\\\\db", temp.getRoot().getAbsolutePath().replace("\\", "\\\\")); } else { content = content.replaceAll("/var/lib/tbds-server/keys/db", temp.getRoot().getAbsolutePath()); } IOUtils.write(content, new FileOutputStream(caConfigTest)); } catch (IOException e) { e.printStackTrace(); TestCase.fail(); } certMan.initRootCert(); }
From source file:org.obm.sync.push.client.SSLContextFactoryTest.java
@Test public void testKeyStoreIsPKCS12() throws Exception { InputStream pkcs12Stream = ClassLoader.getSystemClassLoader().getResourceAsStream("pkcs_pwd_toto.p12"); char[] pkcs12Password = "toto".toCharArray(); KeyStore keyStore = SSLContextFactory.loadPKCS12KeyStore(pkcs12Stream, pkcs12Password); InputStream pkcs12InnerX509 = ClassLoader.getSystemClassLoader().getResourceAsStream("pkcs_inner_x509.crt"); Certificate pkcs12InnerCertificate = CertificateFactory.getInstance("x509") .generateCertificate(pkcs12InnerX509); assertThat(keyStore.getType()).isEqualToIgnoringCase("pkcs12"); assertThat(keyStore.getCertificate("client2")).isEqualTo(pkcs12InnerCertificate); }
From source file:no.abmu.abmstatistikk.annualstatistic.util.DataLoaderH2.java
public DataLoaderH2(String[] args) { parseOpts(args);//from w w w . j a v a2s. c om Properties properties = new Properties(); String hibFile = System.getProperty(HIB_FILE_KEY, "conf/hibernate/hibernate.properties"); try { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream(hibFile)); dialect = (String) properties.get(HIB_DIALECT_KEY); if (dialect == null) { throw new IllegalAccessException("The file " + hibFile + " had no key " + HIB_DIALECT_KEY); } } catch (Exception e) { initException = e; } System.getProperties().setProperty("applicationContextConfig", "conf/spring/application-context.xml"); System.getProperties().setProperty("config_locs_cp", "conf/spring/appContext-util.xml," + "conf/spring/appContext-configuration.xml," + "conf/spring/appContext-db-dataLayer.xml," + "conf/spring/appContext-service-orgRegister.xml," + "conf/spring/appContext-service-annualStatistic.xml," + "conf/spring/appContext-service-user.xml"); /* + "conf/spring/appContext-security.xml" */ System.getProperties().setProperty("config_locs", ""); ApplicationContextLoaderH2.getInstance().init(); context = ApplicationContextLoaderH2.getInstance().getApplicationContext(); asService = (AnnualStatisticService) ApplicationContextLoaderH2.getInstance().getApplicationContext() .getBean("AnnualStatisticService"); organisationUnitService = (OrganisationUnitService) ApplicationContextLoaderH2.getInstance() .getApplicationContext().getBean("organisationUnitService"); if (organisationUnitService == null) { log.error("Couldn't find organisationUnitService bean"); } loadData(); }
From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java
@Before public void load() throws ClassNotFoundException { this.eventImpl = Class.forName(PORE_PREFIX + event, true, ClassLoader.getSystemClassLoader()); assumeTrue(Event.class.isAssignableFrom(eventImpl)); }
From source file:tr.com.serkanozal.jcommon.util.ClasspathUtil.java
private static Set<URL> findClasspathUrls() { Set<URL> urls = new HashSet<URL>(); try {// w w w . j a v a 2 s . co m String[] classpathProperties = System.getProperty("java.class.path").split(File.pathSeparator); for (String classpathProperty : classpathProperties) { urls.add(new File(classpathProperty).toURI().toURL()); } } catch (MalformedURLException e) { logger.error("Error occured while getting classpath from system property \"java.class.path\"", e); } String surefireProperty = System.getProperty("surefire.test.class.path"); if (StringUtils.isNotEmpty(surefireProperty)) { try { String[] surefireClasspathProperties = surefireProperty.split(File.pathSeparator); for (String surefireClasspathProperty : surefireClasspathProperties) { urls.add(new File(surefireClasspathProperty).toURI().toURL()); } } catch (MalformedURLException e) { logger.error( "Error occured while getting classpath from system property \"surefire.test.class.path\"", e); } } // Start with Current Thread's loader ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); ClassLoader loader = ctxLoader; while (loader != null) { urls.addAll(findClasspathsByLoader(loader)); loader = loader.getParent(); } // Also start with this classes's loader, in some environment this can // be different than the current thread's one ClassLoader appLoader = ClasspathUtil.class.getClassLoader(); loader = appLoader; while (loader != null) { urls.addAll(findClasspathsByLoader(loader)); loader = loader.getParent(); } ClassLoader sysLoader = ClassLoader.getSystemClassLoader(); loader = sysLoader; while (loader != null) { urls.addAll(findClasspathsByLoader(loader)); loader = loader.getParent(); } Map<URL, URL> replaceURLs = new HashMap<URL, URL>(); Set<URL> derivedUrls = new HashSet<URL>(); for (URL url : urls) { if (url.getProtocol().startsWith("vfs")) { try { URLConnection conn = url.openConnection(); Object virtualFile = conn.getContent(); if (virtualFile.getClass().getName().equals("org.jboss.vfs.VirtualFile")) { File file = (File) virtualFile.getClass().getMethod("getPhysicalFile").invoke(virtualFile); String fileName = file.getCanonicalPath(); String name = (String) virtualFile.getClass().getMethod("getName").invoke(virtualFile); name = name.trim().toLowerCase(); if ((name.endsWith("jar") || name.endsWith("zip") && fileName.endsWith("/contents"))) { fileName = fileName.replace("contents", name); } URL repURL = new URL("file:/" + fileName); replaceURLs.put(url, repURL); } } catch (Exception e) { // We don't expect to trapped here e.printStackTrace(); } } try { if (url.toExternalForm().endsWith("WEB-INF/classes")) { derivedUrls.add(new URL(url.toExternalForm().replace("WEB-INF/classes", "WEB-INF/lib"))); } else if (url.toExternalForm().endsWith("WEB-INF/classes/")) { derivedUrls.add(new URL(url.toExternalForm().replace("WEB-INF/classes/", "WEB-INF/lib/"))); } } catch (Exception e) { e.printStackTrace(); } } urls.removeAll(replaceURLs.keySet()); urls.addAll(replaceURLs.values()); urls.addAll(derivedUrls); replaceURLs.clear(); //Check contained urls for (URL url : urls) { for (URL rootUrl : urls) { if (url.equals(rootUrl)) { continue; } if (url.toExternalForm().startsWith(rootUrl.toExternalForm())) { if (replaceURLs.get(url) != null) { URL settledUrl = replaceURLs.get(url); if (settledUrl.toExternalForm().startsWith(rootUrl.toExternalForm())) { replaceURLs.put(url, rootUrl); } } else { replaceURLs.put(url, rootUrl); } } } } urls.removeAll(replaceURLs.keySet()); return urls; }
From source file:com.jiminger.util.LibraryLoader.java
private static InputStream getInputStream(String resource) { // I need to find the library. Let's start with the "current" classloader. // see http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html // also see: http://www.javaworld.com/javaworld/javaqa/2003-03/01-qa-0314-forname.html InputStream is = getInputStreamFromClassLoader(LibraryLoader.class.getClassLoader(), resource); if (is == null) // ok, now try the context classloader is = getInputStreamFromClassLoader(Thread.currentThread().getContextClassLoader(), resource); if (is == null) // finally try the system classloader though if we're here we're probably screwed is = getInputStreamFromClassLoader(ClassLoader.getSystemClassLoader(), resource); return is;//from ww w . j av a 2s . c om }
From source file:org.pdfsam.guiclient.GuiClient.java
/** * Loads the libraries in the "ext" subdirectory *///from w ww .j a v a 2 s . c o m private static void loadExtendedLibraries() { try { String configSearchPath = new File(URLDecoder .decode(GuiClient.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8")) .getParent(); File currentDir = new File(configSearchPath, "ext"); File[] fileList = currentDir.listFiles(new JarFilter(false)); if (!ArrayUtils.isEmpty(fileList)) { URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); for (File currentFile : fileList) { addJar(currentFile.toURI().toURL(), urlClassLoader); } ThumbnailCreatorsRegisty.reload(urlClassLoader); } } catch (Exception e) { log.error("Unable to load extended libraries.", e); } }