Classloader resource paths are always absolute?

一世执手 提交于 2019-12-01 19:16:37

Apparently not.

It is up to the class loader to interpret name in getResource(name).

Examining the source code of URLClassLoader, eventually it calls

new URL(baseURL, name)

It is important here whether name is absolute or relative

It is possible that, for some baseURL, absolute /foo/bar and relative foo/bar have the same effect. In particular, this is always the case for "jar file URL" in classpaths

baseURL:       jar:file:/home/duke/duke.jar!/

 foo/bar  ->   jar:file:/home/duke/duke.jar!/foo/bar 
/foo/bar  ->   jar:file:/home/duke/duke.jar!/foo/bar 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!