public class BlankIcon { public BlankIcon() {} }
When I track down how this class is used, I find it's used like this:
BlankIcon.class.getResource("name_of_file_to_load");
After talking to Scott and a few other folks online, they pointed me to the java.lang.ClassLoader class. Specifically, the ClassLoader.getSystemClassLoader().getResource() method. I replaced all instances of the BlankIcon code above with calls to:
ClassLoader.getSystemClassLoader().getResource("path/to/name_of_file_to_load");
So, I made 2 changes. First, changing to the ClassLoader's getResource() method, and changing from just providing the name of the file to providing the full path to the file. The second change is necessary because the old BlankIcon class used to reside in the same package as the files to be loaded.
So I go and test my wonderful new code from within my IDE (JBuilder4 on Linux). Works like a charm. I check in my code to CVS. Other developers grab the code, test it, use it, it works great from within their IDEs (all the same environment).
Release testing day comes. We package everything up into a JAR file. We deploy the JAR to our testing site. We test the JAR applet.
Shit breaks left and right. And where does it break? At the calls to ClassLoader.getSystemClassLoader().getResource("path/to/name_of_file_to_load"); of course.
This was last Thursday, and I'll be damned if I can remember the exact error that was getting thrown, or else I'd post it here. However, I'm wondering if anyone else has run across similar problems, and if so, what's the best route to fix them?
For now, we've gone back to the old BlankIcon.class.getResource() style of doing things. As one of the other programmers here says, this is a "squinky hack." Why doesn't the ClassLoader way of doing things work inside a JAR?