• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to access folder 'resources/images' programmatically?

 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

I have folder with many images at /myProjectRoot/resources/images/

How to access this folder in managed bean so that I am able to get names of all files(images) from it?

Thank you!
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this is an absolute filesystem path, create a java.io.File object from its value and use the File list() method.

If this is a resource within the WAR. you may may find this to be a harder task. As far as I can determine, you would have to use the getRealPath() method to contruct a File from that resource path, then list() it. However, that will only work on exploded WARs - it's not "write once, run anywhere". For cases like that, it's often easier to just keep a file in the WAR with the list of image names in it and read that as a stream resource.
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Tim!

I am glad to inform you that I coped with this task.
I keep my plain file where I list names of 50 images in separate folder called domain2/lib/JavaHelp/other where I also keep all uploaded photos.
It is outside my deployed project.
domain2/lib/JavaHelp/other is virtual directory which I registered on glassfish very easily as described at http://www.marceble.com/2009/07/virtual-directories-in-glassfish/
Then I read data from url by this piece of code:

Isn't it great approach?
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Volodymyr Levytskyi wrote:Hello Tim!

I am glad to inform you that I coped with this task.
I keep my plain file where I list names of 50 images in separate folder called domain2/lib/JavaHelp/other where I also keep all uploaded photos.
It is outside my deployed project.
domain2/lib/JavaHelp/other is virtual directory which I registered on glassfish very easily as described at http://www.marceble.com/2009/07/virtual-directories-in-glassfish/
Then I read data from url by this piece of code:

Isn't it great approach?



I don't know. Can it throw an IOException? If so, your close may get bypassed and you could leak resources.
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

Maybe the idea with virtual directories is cool and it works for me, but I finally stopped on env-entry because if path to file changes I would have to modify class itself in case of virtual directories, but with env-entry I need to modify web.xml only which I hope is less complicated.

Thank you!
 
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic