Put your properties file on your classpath i.e /WEB-INF/classes/

I have this simple class that I use to load props, tho there are lots of
different ways to do this using the JDK:

import java.util.Properties;
import java.io.*;

/**
 * Utility class with static method(s) to load resources for axis
 * application.
 * @version     1.0
 * @author      Adam Leggett  <[EMAIL PROTECTED]>
 */
public class PropertyResourceLoader {

        /**
         * Returns a <code>Properties</code> instance loaded with name value
         * pairs from properties file on classpath
         * @param filename the name of the properties file.
         * @return java.util.Properties the collection of name value pairs
         * specified in the properties file.
         * @exception java.io.IOException
         */
        public static Properties loadProperties(String filename) throws
IOException
        {
                //get file as InputStream
                InputStream is =
PropertyResourceLoader.class.getClassLoader().getResourceAsStream(filename);
                
                Properties props = new Properties();
                
                //load name value pairs into Properties instance
                props.load(is);
                
                return props;
        }       
}

Cheers

Adam Leggett
UPCO
Direct Line: 0113 20 10 631
Fax: 0113 20 10 666
<http://www.upco.co.uk>
The contents of this email are intended for the named addressees and may
contain confidential and / or privileged material. If received in error,
please contact UPCO on +44 (0)113 20 10 600 and then delete the entire email
from your system. Unauthorised review, distribution, disclosure or other use
of this information could constitute a breach of confidence. Your
co-operation in this matter is greatly appreciated.




-----Original Message-----
From: Steven Gollery [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, February 21, 2002 11:42 PM
To: [EMAIL PROTECTED]
Subject: property files for services


I'm working on a web service that requires the ability to read some
properties from a file when the service starts. I've tried using
Properties.load to read the file, but this only works when I hard-code the
entire path to the file in the code for the web service, which seems
unsatisfactory. I'd like to be able to load the properties file without
assuming a specific directory structure -- probably this means using a path
that is relative to the class file or jar file for the web service, or some
similar approach.

Is there any way for a web service to find a file without relying on a
hard-coded path?

Steven Gollery
[EMAIL PROTECTED]

Reply via email to