tags:

views:

31

answers:

1

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?

+2  A: 

You can use ClassLoader.getResource, specifying a slash-delimited resource path.

Matthew Flaschen
...wherein you pass the JAR-relative path.
BalusC
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
not true - this answer states ClassLoader.getReosurce, which always treats resource names as relatve to the classpath root.
mdma