List of usage examples for java.lang ClassLoader getSystemClassLoader
@CallerSensitive public static ClassLoader getSystemClassLoader()
From source file:org.apache.cayenne.util.ResourceLocator.java
/** * Looks up the URL for the named resource using this class' ClassLoader. *//* w w w . j a v a2 s. c o m*/ public static URL findURLInClasspath(String name) { ClassLoader classLoader = ResourceLocator.class.getClassLoader(); if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } return findURLInClassLoader(name, classLoader); }
From source file:fr.free.nrw.commons.Media.java
@SuppressWarnings("unchecked") public Media(Parcel in) { localUri = in.readParcelable(Uri.class.getClassLoader()); thumbUrl = in.readString();/*from w w w . j av a 2 s. c o m*/ imageUrl = in.readString(); filename = in.readString(); description = in.readString(); dataLength = in.readLong(); dateCreated = (Date) in.readSerializable(); dateUploaded = (Date) in.readSerializable(); creator = in.readString(); tags = (HashMap<String, Object>) in.readSerializable(); width = in.readInt(); height = in.readInt(); license = in.readString(); if (categories != null) { in.readStringList(categories); } descriptions = in.readHashMap(ClassLoader.getSystemClassLoader()); }
From source file:org.programmatori.domotica.own.server.engine.EngineManagerImpl.java
private void loadPlugIn() { //org.programmatori.domotica.bticino.map.Map map = new org.programmatori.domotica.bticino.map.Map(this); //map.start(); List<String> plugins = Config.getInstance().getPlugIn(); for (Iterator<String> iter = plugins.iterator(); iter.hasNext();) { String nameClass = (String) iter.next(); try {//from w w w . ja v a 2 s . co m Class<?> c = ClassLoader.getSystemClassLoader().loadClass(nameClass); @SuppressWarnings("unchecked") Constructor<PlugIn> constructor = (Constructor<PlugIn>) c.getConstructor(EngineManagerImpl.class); PlugIn plugIn = constructor.newInstance(this); plugIn.start(); log.info(plugIn.getClass().getSimpleName() + " started!"); } catch (Exception e) { log.error(LogUtility.getErrorTrace(e)); } } }
From source file:de.uniko.west.winter.core.serializing.JSONResultProcessor.java
private static Map<String, Set<Object>> convertJson2Map(JSONObject jsonResultObj) throws WinterException { JSONObject headObj = null;/*from w w w . j a v a2s . co m*/ JSONObject resultObj = null; JSONArray vars = null; JSONArray results = null; try { headObj = jsonResultObj.getJSONObject(KEY_HEAD); resultObj = jsonResultObj.getJSONObject(KEY_RESULTS); vars = headObj.getJSONArray(KEY_VARS); results = resultObj.getJSONArray(KEY_BINDINGS); if (headObj == null || resultObj == null || vars == null || results == null) { throw new NullPointerException("Essential elements in JSONObject are null!"); } } catch (Exception e) { throw new WinterException("Missing essential elements in JSON result object!", e); } Map<String, Set<Object>> bindingMap = new HashMap<String, Set<Object>>(); for (int j = 0; j < results.length(); j++) { for (int i = 0; i < vars.length(); i++) { Object value = null; String key = null; try { key = vars.getString(i); if (!bindingMap.containsKey(key)) { bindingMap.put(key, new HashSet<Object>()); } String valueString = results.getJSONObject(j).getJSONObject(key).getString("value"); String type = results.getJSONObject(j).getJSONObject(key).getString("type"); if (type.equalsIgnoreCase("uri")) { value = new URI(valueString); } else if (type.equalsIgnoreCase("literal")) { value = valueString; } else if (type.equalsIgnoreCase("typed-literal")) { URI typeURI = new URI(results.getJSONObject(j).getJSONObject(key).getString("datatype")); String datatype = ((String) typeURI.getPath() .substring(typeURI.getPath().lastIndexOf("/") + 1)).trim(); // Trying java primitives // creating new primitive wrapper object by using its constructor with String parameter // e.g. Integer: value = new Integer(valueString); value = Class .forName( "java.lang." + datatype.substring(0, 1).toUpperCase() + datatype.substring(1).toLowerCase(), true, ClassLoader.getSystemClassLoader()) .getConstructor(String.class).newInstance(valueString); } else { throw new WinterException("Wrong Type"); } } catch (Exception e) { e.printStackTrace(); } if (key != null && value != null) { bindingMap.get(key).add(value); } } } // remove entries with empty set for (int i = 0; i < bindingMap.size(); i++) { Object key = bindingMap.keySet().toArray()[i]; if (bindingMap.get(key).isEmpty()) { bindingMap.remove(key); i--; } } return bindingMap; }
From source file:io.dstream.tez.utils.HadoopUtils.java
/** * Will provision current classpath to YARN and return an array of * {@link Path}s representing provisioned resources * If 'generate-jar' system property is set it will also generate the JAR for the current * working directory (mainly used when executing from IDE) *//*from ww w . j ava 2s .c o m*/ private static Path[] provisionClassPath(FileSystem fs, String applicationName, String[] classPathExclusions) { String genJarProperty = System.getProperty(TezConstants.GENERATE_JAR); boolean generateJar = genJarProperty != null && Boolean.parseBoolean(genJarProperty); List<Path> provisionedPaths = new ArrayList<Path>(); List<File> generatedJars = new ArrayList<File>(); boolean confFromHadoopConfDir = generateConfigJarFromHadoopConfDir(fs, applicationName, provisionedPaths, generatedJars); TezConfiguration tezConf = new TezConfiguration(fs.getConf()); boolean provisionTez = true; if (tezConf.get("tez.lib.uris") != null) { provisionTez = false; } URL[] classpath = ((URLClassLoader) ClassLoader.getSystemClassLoader()).getURLs(); for (URL classpathUrl : classpath) { File f = new File(classpathUrl.getFile()); if (f.isDirectory()) { if (generateJar) { String jarFileName = ClassPathUtils.generateJarFileName("application"); f = doGenerateJar(f, jarFileName, generatedJars, "application"); } else if (f.getName().equals("conf") && !confFromHadoopConfDir) { String jarFileName = ClassPathUtils.generateJarFileName("conf_application"); f = doGenerateJar(f, jarFileName, generatedJars, "configuration"); } else { f = null; } } if (f != null) { if (f.getName().startsWith("tez-") && !provisionTez) { logger.info("Skipping provisioning of " + f.getName() + " since Tez libraries are already provisioned"); continue; } String destinationFilePath = applicationName + "/" + f.getName(); Path provisionedPath = new Path(fs.getHomeDirectory(), destinationFilePath); if (shouldProvision(provisionedPath.getName(), classPathExclusions)) { try { provisioinResourceToFs(fs, new Path(f.getAbsolutePath()), provisionedPath); provisionedPaths.add(provisionedPath); } catch (Exception e) { logger.warn("Failed to provision " + provisionedPath + "; " + e.getMessage()); if (logger.isDebugEnabled()) { logger.trace("Failed to provision " + provisionedPath, e); } } } } } for (File generatedJar : generatedJars) { try { generatedJar.delete(); } catch (Exception e) { logger.warn("Failed to delete generated jars", e); } } return provisionedPaths.toArray(new Path[] {}); }
From source file:org.apache.openejb.util.classloader.URLClassLoaderFirst.java
public URLClassLoaderFirst(final URL[] urls, final ClassLoader parent) { super(urls, parent); system = ClassLoader.getSystemClassLoader(); }
From source file:boa.evaluator.BoaEvaluator.java
public void evaluate() { final String[] actualArgs = createHadoopProgramArguments(); final File srcDir = new File(this.COMPILATION_DIR); try {/* w w w . j av a2 s . com*/ final URL srcDirUrl = srcDir.toURI().toURL(); final ClassLoader cl = new URLClassLoader(new URL[] { srcDirUrl }, ClassLoader.getSystemClassLoader()); final Class<?> cls = cl.loadClass("boa." + jarToClassname(this.PROG_PATH)); final Method method = cls.getMethod("main", String[].class); method.invoke(null, (Object) actualArgs); } catch (final Throwable e) { System.err.print(e); } }
From source file:eu.eidas.auth.engine.core.impl.SignP12.java
private InputStream loadFileProperties(String fileConf) throws IOException { InputStream fileProperties = null; try {/* w w w . j a v a 2 s .c o m*/ LOG.trace("File to load " + fileConf); fileProperties = new FileInputStream(fileConf); getProperties().loadFromXML(fileProperties); } catch (Exception e) { LOG.info("Unable to load external file, trying in classpath"); fileProperties = SignP12.class.getResourceAsStream("/" + fileConf); if (fileProperties == null) { fileProperties = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileConf); if (fileProperties == null) { Enumeration<URL> files = ClassLoader.getSystemClassLoader().getResources(fileConf); if (files != null && files.hasMoreElements()) { LOG.debug("file loaded"); fileProperties = ClassLoader.getSystemClassLoader() .getResourceAsStream(files.nextElement().getFile()); } else { throw new IOException("ERROR : File not found" + fileConf, e); } } } } return fileProperties; }
From source file:wasr.UserSettings.java
public static Document getDomResource(String resourceName) { InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream(RESOURCE_FOLDER + resourceName); if (in == null) { File customFile = new File(getFolder(), resourceName); if (customFile.exists()) { try { in = new BufferedInputStream(new FileInputStream(customFile)); } catch (FileNotFoundException ignore) { // already checked if it exists. }//from w w w . j av a2s .co m } } if (in == null) { return null; } SAXBuilder builder = new SAXBuilder(); try { return builder.build(in); } catch (JDOMException e) { LOG.warn(e); return null; } catch (IOException e) { LOG.warn(e); return null; } }
From source file:com.link_intersystems.lang.reflect.Class2Test.java
@Test public void getClassLoaderForSystemClass() throws ClassNotFoundException { Class2<String> class2 = Class2.get(String.class); ClassLoader classLoader = class2.getType().getClassLoader(); assertNull(classLoader);/*from w w w . ja v a 2s . com*/ ClassLoader classLoader2 = class2.getClassLoader(); assertEquals(ClassLoader.getSystemClassLoader(), classLoader2); Class2<Object> class2ByName = Class2.get(String.class.getCanonicalName()); Assert.assertSame(class2, class2ByName); }