aspose file tools*
The moose likes Java in General and the fly likes finding certain files in a jar using ClassLoader.getResources() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "finding certain files in a jar using ClassLoader.getResources()" Watch "finding certain files in a jar using ClassLoader.getResources()" New topic
Author

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

Stuart Rogers
Ranch Hand

Joined: Oct 02, 2008
Posts: 135
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

Joined: Oct 13, 2005
Posts: 38363
    
  23
Too difficult a question for us who are "beginning". Moving discussion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finding certain files in a jar using ClassLoader.getResources()