Loading Resources from a Static Class in Java
Comments available as RSS 2.0
If you’ve ever needed a static method to load a resource, there’s a lot of conflicting information about how to get a resource contained in your JAR. I tried SomeProg.class.getClassLoader() and a few others but ended up with either a null value or an exception. Eventually on a whim I tried the following, which worked.
The package is lime49.lockcrypt, and the file is located in the build path. As it happens I was loading a Chinese font.
InputStream in = LockCrypt.class.getClassLoader().getResourceAsStream("lime49/lockcrypt/fireflysung.ttf"); Font font = Font.createFont(Font.TRUETYPE_FONT, in);

Omg I just spent hours trying to figure out why a sound I was loading was playing when I compiled and ran, but not when i ran my .jar file!
THANK YOU SO MUCH DUDE