[nOs]
"Nils Olav Selåsdal" schrieb:
foo.bar.MyClass.getClass().getResource(filename) returns a URL to a file
foo.bar.filename
while foo.bar.MyClass.getClass().getResource("/"+filename)
would return an URL to filename without the packagename.
Immo
(i.e i get a nullpointerexception calling the getResource() on a "null"
object)
Jonathan Knight
Senior Software Engineer
ARMATURE
Tel: 0113 2595247
Email JKn...@Armature.com
ImageIcon icon;
java.net.URL url;
// Specifying URL instead of file name is a little slower,
// but it works both from files and from .jar.
url = ClassLoader.getSystemResource("images/a2.gif");
icon = (url != null) ? new ImageIcon( url ) : null;
Relative path starts at the "top" of your jar.
I'm reacting to following parts of "Nils Olav Selåsdal" <nose...@frisurf.no>'s
article in comp.lang.java.programmer on Wed, 5 Jul 2000 08:06:11 +02006
.
. Immo Benjes <ben...@ifn.ing.tu-bs.de> wrote in message
. news:39621CAF...@ifn.ing.tu-bs.de...
. >
. >
. > "Nils Olav Selåsdal" schrieb:
. >
. > > I wanna pack my class files in a jar. I'm using som txt files and
. images,
. > > as far as i can remember i used getClass().getResource("filename");
. > > to retrieve data from a jar file.....
. > > Ths works fine before i pack the class files in a jar, but when they're
. > > stored ia a jar, the getClass() returns null!! help!
. > > (using j2se v1.3 on WinNT).
. > >
. > > [nOs]
. >
. > foo.bar.MyClass.getClass().getResource(filename) returns a URL to a file
. > foo.bar.filename
. so in my instance of foo.bar.MyClass, i should be able to say:
. this.getClass().getResource(filename).
. ok,?
. this works fine before i pack my classes in a jar.(have all the directory
. structure)
. once foo.bar.MyClass is stored in a jar, the getClass() returns null ;-(
.
. (i.e i get a nullpointerexception calling the getResource() on a "null"
. object)
.
.
. > while foo.bar.MyClass.getClass().getResource("/"+filename)
. > would return an URL to filename without the packagename.
. >
. > Immo
. >
. >
. >
.
Greetings,
Dirk Bosmans
http://users.belgacombusiness.net/arci/
- Applicet Framework: turns Applets into Applications
- ArciMath BigDecimal: now with BigDecimalFormat
Do i need to use the getClass() method if i want to use the .class fiels i
packed inside the jar file? I am trying to include some of the javax.swing
lasses into my jar, but i am not sure it is working...
thanks,
Tarek