Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2005

Tip: Looking for answers? Try searching our database.

jar files and resources !!

Thread view: 
esamsalah@gmail.com - 18 Apr 2005 13:16 GMT
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
Arnaud Berger - 18 Apr 2005 13:45 GMT
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

> Dear All
>
[quoted text clipped - 9 lines]
>
> Thanks
Thomas Weidenfeller - 18 Apr 2005 14:51 GMT
> Dear All
>
> what is best :
>
> to include resources (images,text files,etc) in the JAR
> or to leave then as external

Include them in the jar. It makes it much easier to distribute an
application. The performance difference - if there is any - shouldn't
usually matter.

> for both is there a difference between loading a resource from the JAR
> and from the FileSystem

> I need an example please.

Why don't you write a small test program for yourself, and measure it?

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.