File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Get a files in the classpath that match a given pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Get a files in the classpath that match a given pattern" Watch "Get a files in the classpath that match a given pattern" New topic
Author

Get a files in the classpath that match a given pattern

Marcio F. Lima
Greenhorn

Joined: Feb 11, 2010
Posts: 1
Hello guys!

Let me try to explain what I need.

I have some config files in my classpath in both the classes directory and inside some jars also.
They follow a predefined naming convention. I'd like to get their contents. The problem is that they are in different subdirectories. Here's the example:

I'd like to have the reference to each of these files so that I can load them using ResourceBundle.getBundle(configFileFQN).

I don't think there's a method I can use to retrieve these files, I guess I'll need to look for them in each package or something. I don't know.

Does anyone have a clue?

Thanks in advance!

Marcio Fernandes de Lima
[ e-mail address and phone number deleted ]
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

Hello Marcio, welcome to JavaRanch.

I deleted your e-mail address and phone number from your post. It's better not to post personal contact details on Internet forums like that. Did you know that there are hackers who search the Internet with automated tools to harvest things like e-mail addresses? They'll put you on spam lists and your inbox will be filled with spam e-mail. Likewise, I don't think it's a good idea to shout your personal phone number to the whole world.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 362

Hi Marcio,

I am not sure if I have understood your requirement correctly. See if the below code helps you:



I hope it helps otherwise let us know what exactly you are looking for?>


Pawan Chopra
SCJP - DuMmIeS mInD
Srikanth Nalam
Greenhorn

Joined: Feb 23, 2010
Posts: 20
Hi Marcio,

I think you don't have to worry about in which jar or directory the files are.

To load the content from the properties file
1.Ensure that it is in classpath
2.Note down the the full qualified name of that file (ex: com.company.module5.config.properties)
3.Pass that full qualified name to the getBundle method of ResourBudle to get the reference and load data.


Thanks & Regards,
Srikanth Nalam.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Get a files in the classpath that match a given pattern
 
Similar Threads
Missing packages mean what?
Delivering configuration files to client
Accessing files that are there in classes directory
How to read properties file in netbeans?
Jar a project with property files in it external to jar