Skip to content

Commit

Permalink
fix to find correct resource without "/" in class loader
Browse files Browse the repository at this point in the history
  • Loading branch information
jumperchen committed Sep 6, 2023
1 parent 9b8c9a9 commit 00bdb92
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions zcommon/src/main/java/org/zkoss/util/resource/ClassLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,14 @@ public String getDirectory() {
public URL getResource(String name) {
// no need to use Classes.getContextClassLoader() here because of the loading order issue
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
final URL url = cl != null ? cl.getResource(resolveName(name)): null;
return url != null ? url: ClassLocator.class.getResource(name);
URL url = cl != null ? cl.getResource(resolveName(name)): null;
if (url != null) {
return url;
} else {
url = ClassLocator.class.getResource(name);
}
// fix if name is not starts with "/", then The getClassLoader() can find the current one.
return url != null ? url : ClassLocator.class.getClassLoader().getResource(name);
}
public InputStream getResourceAsStream(String name) {
// no need to use Classes.getContextClassLoader() here because of the loading order issue
Expand Down

0 comments on commit 00bdb92

Please sign in to comment.