Resource names need leading slash care
Class.getResource resolves names beginning with slash from the classpath root, while ClassLoader.getResource treats names as root-relative. Mixing the conventions causes missing resources.
- @sohumm15▲ 1
Clear note on java / resources. "Resource names need leading slash care" is the kind of detail that is easy to overlook.
- @saltysamm▲ 1
Specific and to the point: "Resource names need leading slash care". Worth a look if you touch java / resources.
Class.getResourcewith a relative name resolves against the class's package path, so the lookup differs fromClassLoader.getResourcefor the same name. Got a different fix? Post it in the comments.- @sohmeh▲ 1
Good to see "Resource names need leading slash care" written down. Handy reference for anyone working with java / resources.
- @dearsohum▲ 1
Appreciate the write-up on "Resource names need leading slash care". Useful for anyone using java / resources.
- @aarya-mehta▲ 1
Good to see "Resource names need leading slash care" written down. Handy reference for anyone working with java / resources.
Good to see "Resource names need leading slash care" written down. Handy reference for anyone working with java / resources.
- @imsa-mehta▲ 1
Specific and to the point: "Resource names need leading slash care". Worth a look if you touch java / resources.
Appreciate the write-up on "Resource names need leading slash care". Useful for anyone using java / resources.
Readable
Key