Reading a properties file under Spring

I have a Spring Webflow 2.0 application running under Tomcat 6.0 that needs to read a properties file. In a bean, I try to open and read the properties file, but no matter where I put the file, the JVM cannot find it (File Not Found exception). I ideally, we'd like the file to reside in the Tomcat config folder or elsewhere at that level. But I cannot find the file in either the application webapp folder or the Tomcat config folder.

How to do?
softechnicsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sathish David Kumar NArchitectCommented:
u can put ur property in class floder.
or in class path
0
Sathish David Kumar NArchitectCommented:
u must define the file name ur xml file(resorces bundel name)
0
Sathish David Kumar NArchitectCommented:
getMessageSourceAccessor().getMessage() u can get the property file value and locale also
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

softechnicsAuthor Commented:
>> u can put ur property in class floder or in class path

You're right, in theory, but it's not working. I do it with other webapps (non-Spring/Weblow) I've previously developed and never had a problem before. I believe there's something unique in Spring/Webflow (amongst other things) that causes it not to work.
0
Mick BarryJava DeveloperCommented:
how are you trying to load it?
you can either use tha classloader and getResource() methods
or getRealPath() to open it as a file
http://helpdesk.objects.com.au/java/how-to-get-the-path-of-a-file-in-a-web-application
0
Sathish David Kumar NArchitectCommented:
check your property file name and path (resources bundel name )in your xml file !
0
softechnicsAuthor Commented:
Objects,

I'm using the java.util.Properties class, load() and getProperty() methods.
0
softechnicsAuthor Commented:
>> check your property file name and path (resources bundel name )in your xml file !

What .xml file? It's not in web.xml and it's not in app-servlet.xml.
0
Sathish David Kumar NArchitectCommented:
where you definr ur resources bundel name?
0
softechnicsAuthor Commented:
In the java bean that opens the Properties file. There is no resources bundle name in web.xml or app-servlet.xml.
0
Mick BarryJava DeveloperCommented:
> I'm using the java.util.Properties class, load() and getProperty() methods.

what are you passing to load()?
If you're creating a FileInputStream/FileReader then you need to use getRealPath() to get the path
Or if you're loading the properties from your classes/lib folders then use getResourceAsStream()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rajkumar_pbCommented:
What OS are you using for Development?
BTW I am using Ubuntu and i used the below code to make it work

            Properties props = new Properties();        try {
//Absolute path
props.load(new FileInputStream("/home/user114/workspace/login/src
/pgsettings.properties"));

//Relative path - for linux you've to put it under home dir.props.load(new FileInputStream("/pgsettings.properties"));            } catch (FileNotFoundException e) {                  // TODO Auto-generated catch block                  e.printStackTrace();            } catch (IOException e) {                  // TODO Auto-generated catch block                  e.printStackTrace();            }        String user  = props.getProperty("pguser");        System.out.println("Domain is :"+user);
The above code is tested and works flawlessly for me.

For windows you need to put the properties file under WEB-INF folder.
0
softechnicsAuthor Commented:
Used getCanonicalPath(). There is no getRealPath(). But, it got me close enough to figure it out.

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.