Re: jar files and resources !!



Hi,

I can't say anything regarding performance .

However, here is what you want for getting resources from jar :

getClass().getClassLoader().getResourceAsStream(String name)
which gives you an InputStream from the resource.
or
getClass().getClassLoader().getResource(String name)
which gives you the URL of the resource.

if your jar contains image.gif inside a /images directory, name would be
"images/image.gif"

Note that getClass() can be called on an instance, you may also call the
class statically e.g :

MyApp.class.getClassLoader().getResourceAsStream(String name)

Regards,

Arnaud





<esamsalah@xxxxxxxxx> a écrit dans le message news:
1113826580.463711.244740@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Dear All
>
> what is best :
>
> to include resources (images,text files,etc) in the JAR
> or to leave then as external
>
> for both is there a difference between loading a resource from the JAR
> and from the FileSystem
>
> I need an example please.
>
> Thanks
>


.



Relevant Pages

  • Re: Jar modification question
    ... resource into the jarfile. ... packages don't seem to be able to replace files in an existing jar file. ... If I have to use any of these I'll recode the bash script in Python ... add some support for a System property or configuration entry to allow the user to specify a replacement resource path. ...
    (comp.lang.java.programmer)
  • Re: Swing - paintComponent not called
    ... the same package as the class using them. ... Dump the url.toStringto see where it is looking for your resource. ... Use JarLook to dump out the contents of your jar to see where the ... If the long-term trend continues, all fish and seafood species are projected to collapse ...
    (comp.lang.java.programmer)
  • Re: J2ME : fastest way to read lines from text resource into a string array ?
    ... In Java I try to avoid doing any loops of single byte/char operations. ... data from my JAR. ... entire resource on the phones I'm currently working with but I'm ...
    (comp.lang.java.programmer)
  • Re: Swing - paintComponent not called
    ... the same package as the class using them. ... Dump the url.toStringto see where it is looking for your resource. ... Use JarLook to dump out the contents of your jar to see where the ... If the long-term trend continues, all fish and seafood species are projected to collapse ...
    (comp.lang.java.programmer)
  • Re: Question: JWS JAR files and embedded resources.
    ... >>jar file and built an installer. ... > resource should be called. ... include both images and XML files, ...
    (comp.lang.java.help)