Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #21715

Re: resources from JAR files

From BGB <cr88192@hotmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: resources from JAR files
Date 2013-01-25 15:08 -0600
Organization albasani.net
Message-ID <kdusbn$vid$1@news.albasani.net> (permalink)
References <f7a28e33-5e29-45fd-8c15-762e8ee4cdc2@googlegroups.com> <50f885a5$0$286$14726298@news.sunsite.dk>

Show all headers | View raw


On 1/17/2013 5:13 PM, Arne Vajhøj wrote:
> On 1/17/2013 11:30 AM, bob smith wrote:
>> I have some code that reads an image from its JAR file like so:
>>
>> img = ImageIO.read(frame.getClass().getResource("whatever.jpg"));
>>
>> I basically just picked the "frame" object at random to call the
>> getClass() method on it.
>>
>> Is there a way to do this without picking an arbitrary object?  It
>> seems so wrong.
>
> You need to pick either an object or a class.
>
> I think it is relative common to pick either this or the class.
>

FWIW, AFIAK:
it can also be noted that it does matter which class you pick, like 
generally you want the class and resource file to be in the same package 
and JAR and similar (the class basically telling the JVM where to look, 
otherwise the resource may not be found).

so, while a person can pick an arbitrary class, it may not necessarily 
find the resource.

so, generally, picking 'this' or similar makes sense, since normally a 
person will package the resources along with their own code.


or such...

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

resources from JAR files bob smith <bob@coolfone.comze.com> - 2013-01-17 08:30 -0800
  Re: resources from JAR files markspace <markspace@nospam.nospam> - 2013-01-17 08:54 -0800
  Re: resources from JAR files Roedy Green <see_website@mindprod.com.invalid> - 2013-01-17 15:07 -0800
    Re: resources from JAR files Lew <lewbloch@gmail.com> - 2013-01-17 15:16 -0800
      Re: resources from JAR files Roedy Green <see_website@mindprod.com.invalid> - 2013-01-17 16:36 -0800
        Re: resources from JAR files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-17 19:44 -0500
  Re: resources from JAR files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-17 18:13 -0500
    Re: resources from JAR files BGB <cr88192@hotmail.com> - 2013-01-25 15:08 -0600
      Re: resources from JAR files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-25 20:57 -0500
        Re: resources from JAR files Lew <lewbloch@gmail.com> - 2013-01-25 22:32 -0800

csiph-web