List of usage examples for java.lang ClassLoader getSystemClassLoader
@CallerSensitive public static ClassLoader getSystemClassLoader()
From source file:io.hops.util.RMStorageFactory.java
private static void addToClassPath(String s) throws StorageInitializtionException { try {/*from w ww . j a v a 2 s. c om*/ File f = new File(s); URL u = f.toURI().toURL(); URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class urlClass = URLClassLoader.class; Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); method.invoke(urlClassLoader, new Object[] { u }); } catch (MalformedURLException ex) { throw new StorageInitializtionException(ex); } catch (IllegalAccessException ex) { throw new StorageInitializtionException(ex); } catch (IllegalArgumentException ex) { throw new StorageInitializtionException(ex); } catch (InvocationTargetException ex) { throw new StorageInitializtionException(ex); } catch (NoSuchMethodException ex) { throw new StorageInitializtionException(ex); } catch (SecurityException ex) { throw new StorageInitializtionException(ex); } }
From source file:org.java.plugin.ObjectFactory.java
private static Class loadClass(final ClassLoader cl, final String className) throws ClassNotFoundException { if (cl != null) { try {/*from w ww. j av a 2 s. co m*/ return cl.loadClass(className); } catch (ClassNotFoundException cnfe) { // ignore } } ClassLoader cl2 = ObjectFactory.class.getClassLoader(); if (cl2 != null) { try { return cl2.loadClass(className); } catch (ClassNotFoundException cnfe) { // ignore } } return ClassLoader.getSystemClassLoader().loadClass(className); }
From source file:com.mockey.plugin.PluginStore.java
/** * //from w w w . j a v a2 s.com * @param className * @return Instance of a Class with 'className, if implements * <code>IRequestInspector</code>, otherwise returns null. */ private Class<?> doesThisImplementIRequestInspector(String className) { try { try { // HACK: Class<?> xx = Class.forName(className); if (!xx.getName().equalsIgnoreCase(RequestInspectorDefinedByJson.class.getName()) && (!xx.isInterface() && IRequestInspector.class.isAssignableFrom(xx))) { return xx; } } catch (ClassNotFoundException e) { Class<?> xx = ClassLoader.getSystemClassLoader().loadClass(className); if (!xx.isInterface() && IRequestInspector.class.isAssignableFrom(xx)) { return xx; } } } catch (java.lang.NoClassDefFoundError classDefNotFound) { logger.debug("Unable to create class: " + className + "; reason: java.lang.NoClassDefFoundError"); } catch (Exception e) { logger.error("Unable to create an instance of a class w/ name " + className, e); } return null; }
From source file:org.eclipse.wb.tests.designer.core.util.reflect.ReflectionUtilsTest.java
/** * Test for {@link ReflectionUtils#getClassLoader(Class)}. *//*from w w w .ja v a2s. co m*/ public void test_getClassLoader() throws Exception { // "normal" class { Class<?> clazz = getClass(); assertSame(clazz.getClassLoader(), ReflectionUtils.getClassLoader(clazz)); } // "system" class { Class<?> clazz = String.class; assertNull(clazz.getClassLoader()); assertSame(ClassLoader.getSystemClassLoader(), ReflectionUtils.getClassLoader(clazz)); } }
From source file:eu.project.ttc.utils.TermSuiteUtils.java
/** * //from w ww . jav a2 s .c o m */ public static void listClasspath() { ClassLoader cl = ClassLoader.getSystemClassLoader(); URL[] urls = ((URLClassLoader) cl).getURLs(); for (URL url : urls) { System.out.println(url.getFile()); } }
From source file:oz.tez.deployment.utils.ClassPathUtils.java
/** * //from www.j a v a 2s. c o m * @param exclusionFile * @return */ public static String[] initClasspathExclusions(String exclusionFile) { String[] classpathExclusions = null; try { InputStream exclusionResource = ClassLoader.getSystemClassLoader().getResourceAsStream(exclusionFile); if (exclusionResource != null) { List<String> exclusionPatterns = new ArrayList<String>(); BufferedReader reader = new BufferedReader(new InputStreamReader(exclusionResource)); String line; while ((line = reader.readLine()) != null) { exclusionPatterns.add(line.trim()); } classpathExclusions = exclusionPatterns.toArray(new String[] {}); reader.close(); } } catch (Exception e) { logger.warn("Failed to build the list of classpath exclusion. ", e); } return classpathExclusions; }
From source file:me.piebridge.prevent.ui.PreventActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { ThemeUtils.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.main);//from w w w .j a va 2 s. c om ThemeUtils.fixSmartBar(this); mPager = (ViewPager) findViewById(R.id.pager); main = findViewById(R.id.main); actions = findViewById(R.id.actions); removeButton = (Button) findViewById(R.id.remove); preventButton = (Button) findViewById(R.id.prevent); removeButton.setOnClickListener(this); preventButton.setOnClickListener(this); preventButton.setEnabled(false); removeButton.setEnabled(false); receiver = new HookReceiver(); mPageTitles = new String[] { getString(R.string.applications), getString(R.string.prevent_list) }; mPageSelections = new ArrayList<Set<String>>(); mPageSelections.add(new HashSet<String>()); mPageSelections.add(new HashSet<String>()); mPager.setOnPageChangeListener(this); mPager.setAdapter(new ScreenSlidePagerAdapter(getSupportFragmentManager())); HandlerThread thread = new HandlerThread("PreventUI"); thread.start(); mHandler = new Handler(thread.getLooper()); try { ActionBar actionBar = getActionBar(); if (actionBar != null) { actions.setVisibility(View.GONE); } } catch (NoSuchMethodError e) { // NOSONAR // do nothing } try { Class<?> clazz = Class.forName("de.robv.android.xposed.XposedBridge", false, ClassLoader.getSystemClassLoader()); Field field = clazz.getDeclaredField("disableHooks"); field.setAccessible(true); field.set(null, true); } catch (ClassNotFoundException e) { UILog.d("cannot find Xposed", e); } catch (Throwable t) { // NOSONAR UILog.d("cannot disable Xposed", t); } if (!BuildConfig.RELEASE && TextUtils.isEmpty(LicenseUtils.getLicense(this))) { showTestDialog(); } else { init(); } }
From source file:org.lib4j.dbcp.DataSources.java
/** * Create a <code>BasicDataSource</code> given a dbcp JAXB binding. * * @param dbcp JAXB dbcp binding./*ww w.ja va 2s.com*/ * @return the <code>BasicDataSource</code> instance. * @throws SQLException If a database access error occurs. */ public static BasicDataSource createDataSource(final Dbcp dbcp) throws SQLException { return createDataSource(dbcp, ClassLoader.getSystemClassLoader()); }
From source file:com.boundary.metrics.vmware.VMWareTestUtils.java
public static MeterManagerClient getMeterClient() throws Exception { MeterManagerClient client = null;//from ww w .j ava2 s . c o m File propertiesFile = new File(Resources.getResource(DEFAULT_METER_CLIENT_CONFIGURATION).toURI()); Reader reader = new FileReader(propertiesFile); clientProperties = new Properties(); clientProperties.load(reader); String baseUri = clientProperties.getProperty(METER_CLIENT_BASE_URL); String orgId = clientProperties.getProperty(METER_CLIENT_ORG_ID); String apiKey = clientProperties.getProperty(METER_CLIENT_API_KEY); checkArgument(!Strings.isNullOrEmpty(baseUri)); checkArgument(!Strings.isNullOrEmpty(apiKey)); checkArgument(!Strings.isNullOrEmpty(orgId)); ObjectMapper mapper = new ObjectMapper(); MetricRegistry registry = new MetricRegistry(); environment = new Environment("test", mapper, null, registry, ClassLoader.getSystemClassLoader()); String configFile = "vmware-adapter-test.yml"; configuration = VMWareTestUtils.getConfiguration(configFile); Client httpClient = new JerseyClientBuilder(environment).using(configuration.getClient()) .build("http-client"); try { URI uri = new URI(baseUri); client = new MeterManagerClient(httpClient, uri, orgId, apiKey); } catch (URISyntaxException e) { e.printStackTrace(); } return client; }
From source file:org.allcolor.yahp.converter.CClassLoader.java
/** * Creates and allocates a memory URL/* www . j a v a 2 s .c o m*/ * * @param entryName * name of the entry * @param entry * byte array of the entry * @return the created URL or null if an error occurs. */ public static URL createMemoryURL(final String entryName, final byte[] entry) { try { final Class c = ClassLoader.getSystemClassLoader() .loadClass("org.allcolor.yahp.converter.CMemoryURLHandler"); final Method m = c.getDeclaredMethod("createMemoryURL", new Class[] { String.class, byte[].class }); m.setAccessible(true); return (URL) m.invoke(null, new Object[] { entryName, entry }); } catch (final Exception ignore) { ignore.printStackTrace(); return null; } }