List of usage examples for java.lang ClassLoader getResource
public URL getResource(String name)
From source file:Main.java
public static URL loadResource(final String fileName) { ClassLoader c = Thread.currentThread().getContextClassLoader(); return c.getResource(fileName); }
From source file:Main.java
/** * Gets an {@code Icon} given the url {@code resource}. * //from ww w .ja v a 2s. c om * @param resource * the url path to a valid icon * @return An {@code Icon} * @throws RuntimeException if the {@link ClassLoader} could not locate the resource. */ @Deprecated public static Icon getIcon(String resource) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource(resource); if (null == url) { throw new RuntimeException("ClassLoader could not locate " + resource); } return new ImageIcon(url); }
From source file:net.erdfelt.android.sdkfido.logging.Logging.java
public static void config() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("logging.properties"); if (url != null) { InputStream in = null;// w w w . ja va 2 s .co m try { in = url.openStream(); LogManager.getLogManager().readConfiguration(in); } catch (IOException e) { e.printStackTrace(System.err); } finally { IOUtils.closeQuietly(in); } } System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger"); }
From source file:Main.java
/** * @deprecated use {@link ResourceLocator.resourceURL(String)} instead. *///from ww w . j a va 2 s .c o m @Deprecated public static String resourceURL(String name) { ClassLoader tcl = Thread.currentThread().getContextClassLoader(); URL url = tcl.getResource(name); return url != null ? url.toString() : null; }
From source file:org.apache.archiva.common.utils.ResourceUtils.java
private static URL getResourceUrl(String resourcePath, ClassLoader classloader) { return classloader != null ? classloader.getResource(resourcePath) : ResourceUtils.class.getResource(resourcePath); }
From source file:com.frameworkset.common.tag.export.properties.ConfigFactory.java
/** * ?xml???/*from w ww . j ava2 s . com*/ * @param force * @return Configture */ public static Configture createConfigure(boolean force) { Digester digester = new Digester(); digester.setValidating(false); if (configture == null || force) { configture = new Configture(); digester.push(configture); // This set of rules calls the addDataSource method and passes // in five parameters to the method. digester.addBeanPropertySetter("exportconfig/description", "description"); digester.addBeanPropertySetter("exportconfig/version", "version"); digester.addObjectCreate("exportconfig/export", ExportConfig.class); digester.addBeanPropertySetter("exportconfig/export/description", "description"); digester.addSetProperties("exportconfig/export/config", new String[] { "name", "type", "class" }, new String[] { "name", "type", "exportClass" }); digester.addSetNext("exportconfig/export", "addExportConfig"); ClassLoader classLoader = ConfigFactory.class.getClassLoader(); URL url = classLoader.getResource("export.xml"); try { digester.parse(url.openStream()); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } } return configture; }
From source file:com.khs.sherpa.util.Util.java
public static URL getResource(String resource) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); return cl.getResource(resource); }
From source file:com.boundary.sdk.snmp.metric.Pollers.java
public static Pollers load(String resource) throws URISyntaxException { Pollers instance = new Pollers(); ClassLoader classLoader = instance.getClass().getClassLoader(); URL url = classLoader.getResource(resource); File file = new File(url.toURI()); ObjectMapper mapper = new ObjectMapper(); try {//from w ww . j a v a 2s.c o m instance = mapper.readValue(file, Pollers.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return instance; }
From source file:fi.johannes.kata.ocr.utils.ResourceGetter.java
public static URL getUrl(String fileName) { ClassLoader classLoader = ResourceGetter.class.getClassLoader(); URL url = classLoader.getResource(fileName); return url;//from ww w . j av a2 s . c om }
From source file:com.taobao.pushit.commons.ServerLoggerInit.java
public static void initLog() { if (initOK) { return;/*from www.j av a 2 s .c o m*/ } URL url = null; ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null || (url = cl.getResource(PUSHIT_SERVER_LOG4J_FILE)) == null) { cl = ServerLoggerInit.class.getClassLoader(); if (cl == null || (url = cl.getResource(PUSHIT_SERVER_LOG4J_FILE)) == null) { fallback(); return; } } final ClassLoader pre = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(PropertyConfigurator.class.getClassLoader()); PropertyConfigurator.configure(url); } finally { Thread.currentThread().setContextClassLoader(pre); } }