本文整理了Java中java.lang.ClassLoader.getSystemResource()
方法的一些代码示例,展示了ClassLoader.getSystemResource()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassLoader.getSystemResource()
方法的具体详情如下:
包路径:java.lang.ClassLoader
类名称:ClassLoader
方法名:getSystemResource
[英]Finds the URL of the resource with the specified name. The system class loader's resource lookup algorithm is used to find the resource.
[中]查找具有指定名称的资源的URL。系统类加载器的资源查找算法用于查找资源。
代码示例来源:origin: stackoverflow.com
return Paths.get(ClassLoader.getSystemResource(resourceName).toURI());
代码示例来源:origin: stackoverflow.com
java.net.URL url = ClassLoader.getSystemResource("com/xyz/resources/camera.png");
代码示例来源:origin: spring-projects/spring-framework
/**
* Resolves a URL for the underlying class path resource.
* @return the resolved URL, or {@code null} if not resolvable
*/
@Nullable
protected URL resolveURL() {
if (this.clazz != null) {
return this.clazz.getResource(this.path);
}
else if (this.classLoader != null) {
return this.classLoader.getResource(this.path);
}
else {
return ClassLoader.getSystemResource(this.path);
}
}
代码示例来源:origin: Netflix/zuul
private File loadFromResources(String s) {
return new File(ClassLoader.getSystemResource("ssl/" + s).getFile());
}
}
代码示例来源:origin: ethereum/ethereumj
public static ImageIcon getImageIcon(String resource) {
URL imageURL = ClassLoader.getSystemResource(resource);
ImageIcon image = new ImageIcon(imageURL);
return image;
}
代码示例来源:origin: stackoverflow.com
// Load the directory as a resource
URL dir_url = ClassLoader.getSystemResource(dir_path);
// Turn the resource into a File object
File dir = new File(dir_url.toURI());
// List the directory
String files = dir.list()
代码示例来源:origin: apache/hive
public static String getFileFromClasspath(String name) {
URL url = ClassLoader.getSystemResource(name);
if (url == null) {
throw new IllegalArgumentException("Could not find " + name);
}
return url.getPath();
}
代码示例来源:origin: org.springframework/spring-core
/**
* Resolves a URL for the underlying class path resource.
* @return the resolved URL, or {@code null} if not resolvable
*/
@Nullable
protected URL resolveURL() {
if (this.clazz != null) {
return this.clazz.getResource(this.path);
}
else if (this.classLoader != null) {
return this.classLoader.getResource(this.path);
}
else {
return ClassLoader.getSystemResource(this.path);
}
}
代码示例来源:origin: spring-projects/spring-framework
String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length());
ClassLoader cl = ClassUtils.getDefaultClassLoader();
URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path));
if (url == null) {
String description = "class path resource [" + path + "]";
代码示例来源:origin: spring-projects/spring-framework
String description = "class path resource [" + path + "]";
ClassLoader cl = ClassUtils.getDefaultClassLoader();
URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path));
if (url == null) {
throw new FileNotFoundException(description +
代码示例来源:origin: looly/hutool
/**
* 根据给定资源初始化URL
*/
private void initUrl() {
if (null != this.clazz) {
super.url = this.clazz.getResource(this.path);
} else if (null != this.classLoader) {
super.url = this.classLoader.getResource(this.path);
} else {
super.url = ClassLoader.getSystemResource(this.path);
}
if (null == super.url) {
throw new NoResourceException("Resource of path [{}] not exist!", this.path);
}
}
代码示例来源:origin: looly/hutool
/**
* 根据给定资源初始化URL
*/
private void initUrl() {
if (null != this.clazz) {
super.url = this.clazz.getResource(this.path);
} else if (null != this.classLoader) {
super.url = this.classLoader.getResource(this.path);
} else {
super.url = ClassLoader.getSystemResource(this.path);
}
if (null == super.url) {
throw new NoResourceException("Resource of path [{}] not exist!", this.path);
}
}
代码示例来源:origin: log4j/log4j
/**
* Get the URL for this resource.
*
* @param object The object to grab the Classloader from.
* This parameter is quite important from a
* visibility of resources standpoint as the
* hierarchy of Classloaders plays a role.
*
* @param resource The resource to load.
*
* @return If the Resource was found, the URL, otherwise null.
*
* @see Resource
* @see #getResourceAsStream(Object,Resource)
*/
public static URL getResourceAsURL(Object object, Resource resource) {
ClassLoader loader = object.getClass().getClassLoader();
URL url = null;
if (loader != null) {
url = loader.getResource(resource.getName());
} else {
url = ClassLoader.getSystemResource(resource.getName());
}
return (url);
}
代码示例来源:origin: Netflix/zuul
private File loadFromResources(String s) {
return new File(ClassLoader.getSystemResource("ssl/" + s).getFile());
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public URL getResource(String name) {
URL url = findResource(name);
if (url == null)
url = ClassLoader.getSystemResource(name);
if (url == null)
url = super.getResource(name);
return url;
}
代码示例来源:origin: json-path/JsonPath
public static File resourceAsFile(String resource) {
try {
URL systemResource = getSystemResource(resource);
return new File(systemResource.toURI());
} catch (URISyntaxException e) {
throw new AssertionError("URI syntax error:" + e.getMessage());
}
}
}
代码示例来源:origin: ethereum/ethereumj
private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException {
URL url = ClassLoader.getSystemResource(path);
File file = new File(url.toURI());
List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
List<Block> blocks = new ArrayList<>(strData.size());
for (String rlp : strData) {
blocks.add(new Block(decode(rlp)));
}
return blocks;
}
代码示例来源:origin: ethereum/ethereumj
private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException {
URL url = ClassLoader.getSystemResource(path);
File file = new File(url.toURI());
List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
List<Block> blocks = new ArrayList<>(strData.size());
for (String rlp : strData) {
blocks.add(new Block(decode(rlp)));
}
return blocks;
}
代码示例来源:origin: ethereum/ethereumj
private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException {
URL url = ClassLoader.getSystemResource(path);
File file = new File(url.toURI());
List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
List<Block> blocks = new ArrayList<>(strData.size());
for (String rlp : strData) {
blocks.add(new Block(decode(rlp)));
}
return blocks;
}
代码示例来源:origin: ethereum/ethereumj
@Before
public void setup() throws URISyntaxException, IOException, InterruptedException {
blockchain = createBlockchain((Genesis) Genesis.getInstance());
pendingState = ((BlockchainImpl) blockchain).getPendingState();
URL blocks = ClassLoader.getSystemResource("state/47250.dmp");
File file = new File(blocks.toURI());
strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (int i = 0; i < 46000; i++) {
Block b = new Block(Hex.decode(strData.get(i)));
blockchain.tryToConnect(b);
}
}
内容来源于网络,如有侵权,请联系作者删除!