Article View: borland.public.jbuilder.java.swing
Article #9282Re: Loading images from jar file
From: John P. McGrath
Date: Thu, 20 Apr 2000 00:00
Date: Thu, 20 Apr 2000 00:00
23 lines
1444 bytes
1444 bytes
On Wed, 19 Apr 2000 13:33:15 -0600, nathanlaan wrote:
> The getResource methods can only (as far aas I know) find resources at
> the same package level as the class they are being loaded from.
I believe the ClassLoader getResource() method resolves the path relative
to the root of the class hierarchy.
The Class class has a getResource() method that can resolve relative to
the package of the calling class. For example:
URL url = getClass().getResource( "smiley.jpg" );
This will load the from the same path as the ".class" file. If you
specify a relative path (i.e. "images/smiley.jpg"), it will be relative
to the directory that contains the class file. You can also specify an
absolute path (i.e. "/com/company/package/images/smiley.jpg"). This
should be the equivalent of calling the ClassLoader getResource() method.
--
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.136876da5963b67d989897@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38fd824d.4293483@newsgroups.borland.com> <38FDB38D.161605C7@cwcom.co.uk> <38fe0585@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,ec9795bc13a1381d X-Google-Attributes: gid111d45,public From: John P. McGrath <JPMcGrath@fast.net> Subject: Re: Loading images from jar file Date: 2000/04/20 Message-ID: <MPG.136876da5963b67d989897@forums.borland.com> X-Deja-AN: 613483220 References: <38fd824d.4293483@newsgroups.borland.com> <38FDB38D.161605C7@cwcom.co.uk> <38fe0585@dnews> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing