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)
| 188 | * @throws IllegalArgumentException if the resource is not found |
| 189 | */ |
| 190 | @CanIgnoreReturnValue // being used to check if a resource exists |
| 191 | // TODO(cgdecker): maybe add a better way to check if a resource exists |
| 192 | // e.g. Optional<URL> tryGetResource or boolean resourceExists |
| 193 | public static URL getResource(String resourceName) { |
| 194 | ClassLoader loader = |
| 195 | MoreObjects.firstNonNull( |
| 196 | Thread.currentThread().getContextClassLoader(), Resources.class.getClassLoader()); |
| 197 | URL url = loader.getResource(resourceName); |
| 198 | checkArgument(url != null, "resource %s not found.", resourceName); |
| 199 | return url; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Given a {@code resourceName} that is relative to {@code contextClass}, returns a {@code URL} |
no test coverage detected