This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finding certain files in a jar using ClassLoader.getResources()

 
Stuart Rogers
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've built a Java/Hibernate/Swing standalone app that works great when executed from within Eclipse.
I created a runnable jar, in which the GUI part worked but the app stalled when the "DoIt" JButton was clicked.
After a great deal of googling I have a vague understanding that the problem lies with classloaders, and that
one solution is to use ClassLoader.getResource() and/or ClassLoader.getResources()

I know these files are contained in the root directory of the runnable jar:
lamp.cfg.xml
sofa.cfg.xml
desk.cfg.xml

which is to say they are located in the /src directory of my Eclipse project.

a snippet of my HibernateUtil.java:


I don't want to have to hardcode filenames - I want the code to find them, either by the regex used in the third Enumeration or by iterating through all the files in the root directory of the jar and picking out the desired files.

So how can I get
a) ClassLoader.getResources() to return a list (well, enum) of just the files in the root directory of the jar that I want, using the regex
b) ClassLoader.getResources() to return a list (well, enum) of all the files in the root directory of the jar


TIA,

Still-learning Stuart
 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult a question for us who are "beginning". Moving discussion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic