Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Getting a list of images from a jar file

 
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this topic is a little old but I have a similar problem. I can access an image from the executable jar while the application is running using this:

That works fine for 1 image. What I would like to do is read the entire directory of images and load them without having to hardcode the name of each and every image.

The below code works fine from eclipse but when I make an executable jar file, it doesn't work anymore.

In the above code f is a JFrame I created earlier in the code.
I have a piece of code that tries to get the resources

but that points to the workspace where the project is: ......./workspace/Images/bin and that won't work from the runnable jar when I execute the jar from my desktop or from another machine.
how can I access a list of all the .jpg files in my runnable jar without hard coding the names of each of them?
 
Jay Brass
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at some of the other topics in the forum, it looks like one way to read all the images is to create a Table of Contents (TOC) list. It won't be hard to implement but is an extra maintenance step I had hoped to avoid. If I write the code correctly, checking for null, I won't have to worry about the directory of images and the TOC being in sync, as long as the images I want to show are correctly referenced in the TOC.
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic