Arne,
People don't seem to be listening to you about how you have already
tested your code in Eclipse and yet the same code does not work in the
jar file despite your files being in the jar file and in the right
location. A couple days ago in the comp.lang.java.gui newsgroup I
posted a message about this very same problem and so far they have not
been able to help me. I've tried all sorts of combinations of
class.getResource() and classLoader().getResource() and still can't get
icons to load when I use a jar file.
If I run my jar file right above the directory where my icons exist in
my file system then the icons load but that is only because the jar file
is referencing the version if the icons outside of the jar instead of
inside. One person mentioned that the icons need to be in the classpath
but never said how or where to set the classpath. I've tried to set a
classpath in my command window (Windows XP) and then run my jar but it
did not help. If you get the answer please post it so I can try it in
my environment.
yep that's what i find , when my programs don't work.
it's every body else's fault for not listening.
but then I wake up from my dream.
The following code works ( i know because i use it every day)
YOU DO NOT NEED ANY CLASS PATH TO POINT TO YOUR IMAGES IN YOUR ENVIRONMENT,
nor do they need to be on the "class path"
public class MyProvidesReports implements ProvidesReports {
some other code here........
Getpictures(JobParams);
some other code............
private void Getpictures(HashMap ReportParams) {
java.net.URL Source;
java.net.URL Source1;
Source = MyProvidesReports.class.getResource("/Images/Image1.png"); //
this is a fixed format for all java platforms do not use "file.separator
// Source1 = MyProvidesReports.class.getResource("/Images/Chop.png"); //
this is a fixed format for all java platforms do not use "file.separator
// ReportParams.put("MyChop", Source1);
ReportParams.put("CompanyLogo", Source);
}
}
you just need to compile the pictures into a directory
"/Images/Image1.png"
BUT NOTE:
THE CHARACTER CASE, not all platforms ignore the case , "Images" is NOT the
same as "images"
ALSO NOTE
Do not use "file.separator" or strings with paths in, because file separators
are different on each platform.
use the URL class, and a standard separator and it will always work.
the above code is for getting pictures so that their references can be passed
to reports or buttons or whatever.
those 3-5 lines , will save your life every time, on every platform i have
yet tested it on ( windows95/98/se/2000/NT/linux/osx/solaris/yellowdog)