Returns a URL pointing to resourceName if the resource is found using the plain Thread#getContextClassLoader() context class loader. In simple environments, the context class loader will find resources from the class path. In environments where different threads can have diffe
(String resourceName)
| 198 | */ |
| 199 | |
| 200 | @CanIgnoreReturnValue // being used to check if a resource exists |
| 201 | // TODO(cgdecker): maybe add a better way to check if a resource exists |
| 202 | // e.g. Optional<URL> tryGetResource or boolean resourceExists |
| 203 | public static URL getResource(String resourceName) { |
| 204 | ClassLoader loader = MoreObjects.firstNonNull(Thread.currentThread().getContextClassLoader(), Resources.class.getClassLoader()); |
| 205 | URL url = loader.getResource(resourceName); |
| 206 | checkArgument(url != null, "resource %s not found.", resourceName); |
| 207 | return url; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Given a {@code resourceName} that is relative to {@code contextClass}, returns a {@code URL} |
no test coverage detected