I've bundled a JPG inside of my application's JAR file. I need to access it, preferably via a URL object from the code in the same JAR. But I've no idea how to construct the address. I'm guessing it would be a "file:///" but what comes after that?
views:
31answers:
1
+2
A:
You can use ClassLoader.getResource
, specifying a slash-delimited resource path.
Matthew Flaschen
2010-04-30 03:08:38
...wherein you pass the JAR-relative path.
BalusC
2010-04-30 03:09:46
also save yourself potential headaches and use 'absolute classpath paths', ie paths that start with a '/'. Otherwise the path is relative to the class that is calling the code, and can run into problems if the class is part of an inheritance hierarchy that spans packages.
MeBigFatGuy
2010-04-30 04:42:47
not true - this answer states ClassLoader.getReosurce, which always treats resource names as relatve to the classpath root.
mdma
2010-05-01 01:05:02