Here is a teaching class that shows all you need to know about regular
access to properties files, Mehdi:
/* tccjava.toolbox.io.properties.PropertiesManager December 15, 2001
*
* Copyright 2001 Swords and Ploughshares, Ltd. All Rights Reserved.
*
* This software is the proprietary information of Swords and
Ploughshares, Ltd.
* Use is subject to license terms. */
package properties_demo;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.StringTokenizer;public class Demo {
public static void main(String [] params) throws IOException,
FileNotFoundException {
new File(Folder.STORE).mkdirs();
PropertiesManager factory = new PropertiesManager();
factory.setDefaultPropertiesFileLocation("databank", Folder.STORE
+ File.separator + "databank_default.properties");
factory.setApplicationPropertiesFileLocation("databank",
Folder.STORE + File.separator + "databank_application.properties");
factory.setDefaultFile("databank");
factory.setApplicationFile("databank");
factory.setDefaultProperty("databank", "double", "trouble");
factory.setDefaultProperty("databank", "tickle", "ooooo");
factory.setApplicationProperty("databank", "itch", "aaaaa");
factory.setDefaultPropertiesFileLocation("test", Folder.STORE
+ File.separator + "portal_default.properties");
factory.setApplicationPropertiesFileLocation("test", Folder.STORE
+ File.separator + "portal_application.properties");
factory.setDefaultFile("test");
factory.setApplicationFile("test");
factory.setDefaultProperty("test", "pickels", "chomp");
factory.setDefaultProperty("test", "main", "man");
factory.setDefaultProperty("test", "double", "bubble");
factory.setApplicationProperty("test", "radishes", "crunch");
factory.setApplicationProperty("test", "double", "elbuob");
factory.setApplicationProperty("test", "main", "street");
factory.setApplicationProperty("test", "check", "mark");
System.out.println("DEF FILE set app " +
factory.getApplicationProperty("test", "app"));
System.out.println("DEF FILE set tickle " +
factory.getDefaultProperty("test", "tickle"));
System.out.println("APP FILE set itch " +
factory.getApplicationProperty("test", "itch"));
System.out.println("DEF FILE factory main " +
factory.getDefaultProperty("test", "main"));
System.out.println("APP FILE " +
factory.getApplicationProperty("test", "main"));
System.out.println("APP AND DEF FILE " +
factory.getApplicationPropertyWithDefaults("test", "main"));
System.out.println("APP AND DEF FILE " +
factory.getApplicationPropertyWithDefaults("test", "radishes"));
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
System.out.println();
System.out.println("DEF LOC " +
factory.getDefaultPropertiesFileLocation("databank"));
System.out.println("APP LOC " +
factory.getApplicationPropertiesFileLocation("databank"));
System.out.println();
Properties defaultFile2 = new Properties();
Properties applicationFile2 = new Properties();
Properties applicationFileAndDefaultFile2 = new Properties();
System.out.println("DEF FILE " + (defaultFile2 =
factory.getDefaultProperties("databank")));
System.out.println("APP FILE " + (applicationFile2 =
factory.getApplicationProperties("databank")));
System.out.println("APP AND DEF FILE " +
(applicationFileAndDefaultFile2 =
factory.getApplicationPropertiesWithDefaults("databank")));
System.out.println("N.B.:\n\tThe application property file does
not have the property\n");
/////////////////////////////////////////////////////////////////////////
System.out.println("DEF PROP check " +
defaultFile2.getProperty("check"));
System.out.println("APP PROP " +
applicationFile2.getProperty("check"));
System.out.println("APP AND DEF PROP " +
applicationFileAndDefaultFile2.getProperty("check"));
System.out.println("N.B.:\n\tThe default file does not have the
property\n");
/////////////////////////////////////////////////////////////////////////
System.out.println("DEF PROP double " +
defaultFile2.getProperty("double-check"));
System.out.println("APP PROP " +
applicationFile2.getProperty("double-check"));
System.out.println("APP AND DEF PROP " +
applicationFileAndDefaultFile2.getProperty("double-check"));
System.out.println("N.B.:\n\tThe files have conflicting
values\n");
/////////////////////////////////////////////////////////////////////////
System.out.println("DEF PROP main " +
defaultFile2.getProperty("main"));
System.out.println("APP PROP " +
applicationFile2.getProperty("main"));
System.out.println("APP AND DEF PROP " +
applicationFileAndDefaultFile2.getProperty("main"));
System.out.println("DEF FILE set app " +
factory.getApplicationProperty("test", "app"));
System.out.println("DEF FILE set tickle " +
factory.getDefaultProperty("test", "tickle"));
System.out.println("APP FILE set itch " +
factory.getApplicationProperty("test", "itch"));
System.out.println("DEF FILE factory main " +
factory.getDefaultProperty("test", "main"));
System.out.println("APP FILE " +
factory.getApplicationProperty("test", "main"));
System.out.println("APP AND DEF FILE " +
factory.getApplicationPropertyWithDefaults("test", "main"));
System.out.println("DEF FILE " + (defaultFile2 =
factory.getDefaultProperties("databank")));
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
System.out.println();
System.out.println("DEF LOC " +
factory.getDefaultPropertiesFileLocation("test"));
System.out.println("APP LOC " +
factory.getApplicationPropertiesFileLocation("test"));
System.out.println();
Properties defaultFile = new Properties();
Properties applicationFile = new Properties();
Properties applicationFileAndDefaultFile = new Properties();
System.out.println("DEF FILE " + (defaultFile =
factory.getDefaultProperties("test")));
System.out.println("APP FILE " + (applicationFile =
factory.getApplicationProperties("test")));
System.out.println("APP AND DEF FILE " +
(applicationFileAndDefaultFile =
factory.getApplicationPropertiesWithDefaults("test")));
System.out.println("\\n\\tThe application property file does not
have the property\\n");
/////////////////////////////////////////////////////////////////////////
System.out.println("DEF PROP check " +
defaultFile.getProperty("check"));
System.out.println("APP PROP " +
applicationFile.getProperty("check"));
System.out.println("APP AND DEF PROP " +
applicationFileAndDefaultFile.getProperty("check"));
System.out.println("\\n\\tThe default file does not have the
property\\n");
/////////////////////////////////////////////////////////////////////////
System.out.println("DEF PROP double " +
defaultFile.getProperty("double-check"));
System.out.println("APP PROP " +
applicationFile.getProperty("double-check"));
System.out.println("APP AND DEF PROP " +
applicationFileAndDefaultFile.getProperty("double-check"));
System.out.println("\\n\\tThe files have conflicting values\\n");
/////////////////////////////////////////////////////////////////////////
System.out.println("DEF PROP main " +
defaultFile.getProperty("main"));
System.out.println("APP PROP " +
applicationFile.getProperty("main"));
System.out.println("APP AND DEF PROP " +
applicationFileAndDefaultFile.getProperty("main"));
System.out.println();
System.out.println("DEF FILE " + (defaultFile2 =
factory.getDefaultProperties("databank")));
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
System.exit(0);
}
}
/* tccjava December 31, 2001/* tccjava December 31, 2001
*
* Copyright 2001 Swords and Ploughshares, Ltd. All Rights Reserved.
*
* This software is the proprietary information of Swords and
Ploughshares, Ltd.
* Use is subject to license terms. */
/** This class holds the STORE of the JDK presently being created
* @author Micael Padraig Og mac Grene
* @STORE 1.1 January 4, 2002 Made the class uninstantiable and final.
* @since Version 1.0 December 31, 2001 */
final class Folder {
public static final String STORE = "C:\\STORE";
} ///;-)
/** This class handles everything you need with respect to properties
* files.
* <br><br>
* There are property files for various applications, including default
* and application property files, and there are property files keeping
* track of where the property files for the applications are.
* <br><br>
* The class sets up a master properties file called
* "location.properties," where the addresses of properties files,
* default and application files, for applications are stored.
* The class also adds to and changes properties for default and
* application properties files for applications. Further,
* the class allows you to obtain: (1) default properties,
* (2) application properites, or (3) both default and application
* properties.
* @author Micael Padraig Og mac Grene
* @STORE 1.2 July 28, 2001
* @since 1.0*/
class PropertiesManager {
/** This gives a constant for the LOCATION of the properties
* file holding the LOCATIONs of other properties file. */
public static final String LOCATION = Folder.STORE + File.separator +
"location.properties";
/** A properties object for general use. */
private Properties properties;
public PropertiesManager() {
try {
new File(LOCATION).createNewFile();
} catch (Exception e) {
}
}
/** This method sets a property file holding the LOCATION of
* the default properties files for applications.
* @param app The name of the application.
* @param filePath The filePath you want the LOCATION of the default
property file to have.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound
* @throws java.io.IOException */
public void setDefaultPropertiesFileLocation(String app, String
filePath) throws FileNotFoundException, IllegalArgumentException, IOException {
if(filePath.endsWith("_default.properties")) {
// TODO -- TODO -- TODO -- TODO
// This is not creating the file path.
String path = Path.name(filePath);
File file = new File(Path.name(LOCATION));
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
} else {
properties = new Properties();
}
properties.setProperty(app + "_default", path);
FileOutputStream output = new FileOutputStream(file);
properties.store(output, " -- Properties Manager File -- ");
output.close();
} else {
throw new IllegalArgumentException("You need to use a
properties file ending with the properties name \"<app>_default.properties\"");
}
}
/** This method gets the the LOCATION of the default properties file for
* an application from a property file holding that information.
* @param app The name of the application.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound*/
public String getDefaultPropertiesFileLocation(String app) throws
FileNotFoundException, IllegalArgumentException, IOException {
File file = new File(Path.name(LOCATION));
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
input.close();
} else {
throw new IllegalArgumentException("The manager.properties
file is missing");
}
return properties.getProperty(app + "_default");
}
/** This method sets a property file holding the LOCATION of
* the application properties files for applications.
* @param app The name of the application.
* @param filePath The filePath you want the LOCATION of the
application property file to have.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound */
public void setApplicationPropertiesFileLocation(String app, String
filePath) throws FileNotFoundException, IllegalArgumentException, IOException {
if(filePath.endsWith("_application.properties")) {
String path = Path.name(filePath);
File file = new File(Path.name(LOCATION));
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
} else {
properties = new Properties();
}
properties.setProperty(app + "_application", path);
FileOutputStream output = new FileOutputStream(file);
properties.store(output, " -- Properties Manager File -- ");
output.close();
} else {
throw new IllegalArgumentException("You need to use a
properties file ending with the properties name
\"<app>_application.properties\"");
}
}
/** This method gets the the LOCATION of the application properties
file for
* an application from a property file holding that information.
* @param app The name of the application.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound*/
public String getApplicationPropertiesFileLocation(String app) throws
FileNotFoundException, IllegalArgumentException, IOException {
File file = new File(Path.name(LOCATION));
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
input.close();
} else {
throw new IllegalArgumentException("The manager.properties
file is missing");
}
return properties.getProperty(app + "_application");
}
/** This method creates the default properties file for an application
* @param app The name of the application.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound*/
public void setDefaultFile(String app) throws FileNotFoundException,
IllegalArgumentException, IOException {
File file = new
File(Path.name(getDefaultPropertiesFileLocation(app)));
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
input.close();
} else {
properties = new Properties();
}
FileOutputStream output = new FileOutputStream(file);
properties.store(output, " -- " + app.toUpperCase() + " Default
File -- ");
output.close();
}
/** This method creates the application properties file for an
application.
* @param app The name of the application.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound*/
public void setApplicationFile(String app) throws
FileNotFoundException, IllegalArgumentException, IOException {
File file = new
File(Path.name(getApplicationPropertiesFileLocation(app)));
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
input.close();
} else {
properties = new Properties();
}
FileOutputStream output = new FileOutputStream(file);
properties.store(output, " -- " + app.toUpperCase() + "
Application File -- ");
output.close();
}
/** This method sets the default properties file for an application
* @param app The name of the application.
* @param key The properties name.
* @param value The properties value.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound */
public void setDefaultProperty(String app, String key, String value)
throws FileNotFoundException, IllegalArgumentException, IOException {
File file = new File(getDefaultPropertiesFileLocation(app));
properties = getDefaultProperties(app);
properties.setProperty(key, value);
FileOutputStream output = new FileOutputStream(file);
properties.store(output, " -- " + app + " Default Properties -- ");
output.close();
}
/** This method gets a property from the default properties file for
an application.
* @param app The name of the application.
* @param key The properties name.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound */
public String getDefaultProperty(String app, String key) throws
FileNotFoundException, IllegalArgumentException, IOException {
String path = getDefaultPropertiesFileLocation(app);
if(path != null) {
path = Path.name(path);
File file = new File(path);
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
input.close();
} else {
throw new IllegalArgumentException(app + " default
property file does not exist");
}
} else {
throw new IllegalArgumentException(app + " has not registered
a default property file with the PropertyManager input module.");
}
return properties.getProperty(key);
}
/** This method gets the properties from the default properties file
for an application
* @param app The name of the application.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound */
public Properties getDefaultProperties(String app) throws
FileNotFoundException, IllegalArgumentException, IOException {
String path = getDefaultPropertiesFileLocation(app);
if(path != null) {
path = Path.name(path);
File file = new File(path);
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
input.close();
} else {
throw new IllegalArgumentException(app + " default
property file does not exist");
}
} else {
throw new IllegalArgumentException(app + " has not registered
a default property file with the PropertyManager input module.");
}
return properties;
}
/** This method adds a property to the application properties file for
an application.
* @param app The name of the application.
* @param key The properties name.
* @param value The properties value.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound */
public void setApplicationProperty(String app, String key, String
value) throws FileNotFoundException, IllegalArgumentException, IOException {
File file = new File(getApplicationPropertiesFileLocation(app));
properties = getApplicationProperties(app);
properties.setProperty(key, value);
FileOutputStream output = new FileOutputStream(file);
properties.store(output, " -- " + app + " Application Properties
-- ");
output.close();
}
/** This method gets a particular property from the application
properties file for
*an application.
* @param app The name of the application.
* @param key The properties name.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound */
public String getApplicationProperty(String app, String key) throws
FileNotFoundException, IllegalArgumentException, IOException {
String path = getApplicationPropertiesFileLocation(app);
if(path != null) {
path = Path.name(path);
File file = new File(path);
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
input.close();
} else {
throw new IllegalArgumentException(app + " app property
file does not exist");
}
} else {
throw new IllegalArgumentException(app + " has not registered
a default property file with the PropertyManager input module.");
}
return properties.getProperty(key);
}
/** This method gets a particular property from both the application
properties
* file and the default properties file for an application, with the
application
* properties taking precedence, i.e. overriding the same default
properties.
* @param app The name of the application.
* @param key The properties name.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound */
public String getApplicationPropertyWithDefaults(String app, String
key) throws FileNotFoundException, IllegalArgumentException, IOException {
Properties defaultproperties = getDefaultProperties(app);
String path = getApplicationPropertiesFileLocation(app);
if(path != null) {
path = Path.name(path);
File file = new File(path);
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties(defaultproperties);
properties.load(input);
input.close();
} else {
throw new IllegalArgumentException(app + " app property
file does not exist");
}
} else {
throw new IllegalArgumentException(app + " has not registered
a default property file with the PropertyManager input module.");
}
return properties.getProperty(key);
}
/** This method gets the properties from the application properties file
* for an application.
* @param app The name of the application.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound */
public Properties getApplicationProperties(String app) throws
FileNotFoundException, IllegalArgumentException, IOException {
String path = getApplicationPropertiesFileLocation(app);
if(path != null) {
path = Path.name(path);
File file = new File(path);
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties();
properties.load(input);
input.close();
} else {
throw new IllegalArgumentException(app + " app property
file does not exist");
}
} else {
throw new IllegalArgumentException(app + " has not registered
a default property file with the PropertyManager input module.");
}
return properties;
}
/** This method gets the properties from both the application
properties file
* and the default properties file for an application, with the
application
* properties taking precedence.
* @param app The name of the application.
* @throws java.lang.IllegalArgumentException
* @throws java.io.FileNotFound */
public Properties getApplicationPropertiesWithDefaults(String app)
throws FileNotFoundException, IllegalArgumentException, IOException {
Properties defaultproperties = getDefaultProperties(app);
String path = getApplicationPropertiesFileLocation(app);
if(path != null) {
path = Path.name(path);
File file = new File(path);
if(file.exists()) {
FileInputStream input = new FileInputStream(file);
properties = new Properties(defaultproperties);
properties.load(input);
input.close();
} else {
throw new IllegalArgumentException(app + " app property
file does not exist");
}
} else {
throw new IllegalArgumentException(app + " has not registered
a default property file with the PropertyManager input module.");
}
return properties;
}
/** This method is a helper method that replaces one string for
another in a given
* String object.
* @param content The String object to be worked on.
* @param before The string in the String object to be replaced
throughout.
* @param after The string to act as the replacement throughout the
String
* object */
private static String replace(String content, String before, String
after) {
int position = content.indexOf(before);
while (position > -1) {
content = content.substring(0, position) + after +
content.substring(position + before.length());
position = content.indexOf(before, position + after.length());
}
return content;
}
} ///;-)
/* tccjava.toolbox.io.properties.PropertiesManager December 15, 2001
*
* Copyright 2001 Swords and Ploughshares, Ltd. All Rights Reserved.
*
* This software is the proprietary information of Swords and
Ploughshares, Ltd.
* Use is subject to license terms. */
/** This class makes sure a classpath is platform neutral.
* <code>Path</code> takes a <code>String</code> object representation
* of a classpath (with or without a file name) and replaces the four
* symbols / \ ; and : with their platform neutral <code>File</code> class
* fields.
* @STORE 1.2: 21 April 2001
* @author Micael Padraig Og mac Grene
* @since Version 1.2*/
final class Path {
/** The method <code>name</code> makes a String object classpath platform
* neutral.
* @param path: A <code>String</code> object representation of a
classpath
* @return A <code>String</code> object representation of a platform
neutral
* classpath. */
public static String name(String path) {
replace(path, "\\", File.separator);
replace(path, "/", File.separator);
replace(path, ";", File.pathSeparator);
replace(path, ":", File.pathSeparator);
return path;
}
/** This method is a helper method that replaces one string for
another in a given
* String object.
* @param content The String object to be worked on.
* @param before The string in the String object to be replaced
throughout.
* @param after The string to act as the replacement throughout the
String
* object */
private static String replace(String content, String before, String
after) {
/* This finds the beginning of the first occurence of the string
called
* "before" in the String object called "content". */
int cursor = content.indexOf(before);
while (cursor > -1) {
/* This replaces the string called "before" with the string
called "after".*/
content = content.substring(0, cursor) + after +
content.substring(cursor + before.length());
/* This finds the beginning of the next occurence of the
string called
* "before" in the String object called "content". */
cursor = content.indexOf(before, cursor + after.length());
}
/* This returns the results of replacing instances of strings
identical to
* the string called "before" with instances of strings identical
to the
* string called "after"in the String object called "content". */
return content;
}
} ///;-)
At 05:30 PM 10/8/2002 +0200, you wrote:
>Hi Mehdi,
>
>you could get the resource stream from within a servlet's init()
>method (where you have a ServletContext) and pass it to the
>other object that needs it.
>
>I do it pretty similar. But instead of passing the stream I pass
>the servletContext.
>
>Andreas
>
>
>On 8 Oct 2002 at 15:40, [EMAIL PROTECTED] wrote:
>
> >
> > Hi,
> >
> > There was no ServletContext.getResourceAsStream () ... maybe this is
> > because the whole project is a bunch of utilities for my web-app, and is
> > not a webapp itself ? The class that needs the properties file, is not part
> > of the webapp. So anyway, i tried the closest available method.. (or so i
> > thought);
> >
> > p.load( javax.servlet.ServletContext.class.getResourceAsStream(
> > "/WEB-INF/myprops.properties") );
> >
> > which also did not work.
> >
> > Cheers,
> >
> > Mehdi
> >
> > Mehdi Nejad - Senior Developer
> > [EMAIL PROTECTED]
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Bluewave Ltd - Online Creations
> > http://www.bluewave.com
> > Tel. +44 (0)20 7479 8394
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> >
> >
>
> > "Andreas
> Probst"
>
> > <[EMAIL PROTECTED] To: "Tomcat Users
> List" <[EMAIL PROTECTED]>
> > > cc:
>
> > Subject: Re: How to
> specify the location of a properties file.
> > 08/10/2002
> 13:57
>
> > Please respond
> to
>
> > "Tomcat
> Users
>
> > List"
>
> >
>
> >
>
> >
> >
> >
> >
> > Hi Mehdi,
> >
> > I have my properties file in /WEB-INF. Eclipse doesn't delete it
> > there. I access it with
> >
> > InputStream propsIn = servletContext.getResourceAsStream("/WEB-
> > INF/dms.properties");
> > props.load(propsIn);
> >
> > As far as I know this also works when the web-app ist deployed
> > as a war without expansion.
> >
> > Hope that helps.
> >
> > Andreas
> >
> >
> >
> > On 8 Oct 2002 at 12:48, [EMAIL PROTECTED] wrote:
> >
> > >
> > > I use the getResourceAsStram() method also, but i find that my IDE, tends
> > > to remove the properties file from my classpath, as soon as I do a build,
> > > which is not nice.
> > >
> > > In the particular case i have now, I don't want to specify the parameters
> > > in my web.xml, because the utility that requires a properties file, is
> > not
> > > actually a web-app, rather a bunch of utility classes used by my webapp.
> > > Im not keen to implement a "setProperties()" method, as this would mean
> > > changing stuff, so im just re-copying the properties into my classes
> > folder
> > > after each build.. (unless someone can tell me how to tell WSAD to stop
> > > deleting my properties file... but .. *ahem* thats not a Tomcat question
> > :)
> > >
> > > Cheers,
> > >
> > > Mehdi
> > >
> > >
> > >
> > >
> > >
> >
> > > Justin Ruthenbeck
> >
> > > <justinr@nextengi To: "Tomcat Users
> > List" <[EMAIL PROTECTED]>
> > > ne.com> cc:
> >
> > > Subject: Re: How to
> > specify the location of a properties file.
> > > 07/10/2002 22:20
> >
> > > Please respond to
> >
> > > "Tomcat Users
> >
> > > List"
> >
> > >
> >
> > >
> >
> > >
> > >
> > >
> > >
> > >
> > > Niaz ...
> > >
> > > The idea is to load the properties file like you would any other java
> > > resource at runtime ... this is (almost) always better, IMHO, than using
> > > something J2EE-specific like initialization parameters to a servlet.
> > >
> > > The relevant code would look something like this:
> > >
> > > InputStream inStream = this.getClass().getResourceAsStream("/my.props");
> > > Properties props = new Properties(inStream);
> > >
> > > or
> > >
> > > Properties prop = new Properties();
> > > prop.load(this.getClass().getResourceAsStream
> > ("/MyProperties.properties"));
> > >
> > > There was a thread some time ago that went over this. You can see the
> > > details at:
> > > http://www.mail-archive.com/[email protected]/msg63518.html
> > >
> > > Hope this helps...
> > > justin
> > >
> > >
> > > At 01:40 PM 10/7/2002, you wrote:
> > > >Justin,
> > > >
> > > >I am facing the same problem. Your approach seems to be an elegent one.
> > > >Would you mind eleborating on the idea a little bit more. Some code
> > > snippet
> > > >would definitely be helpful.
> > > >
> > > >I thank you in advance.
> > > >
> > > >niaz.
> > > >----- Original Message -----
> > > >From: "Justin Ruthenbeck" <[EMAIL PROTECTED]>
> > > >To: "Tomcat Users List" <[EMAIL PROTECTED]>
> > > >Sent: Monday, October 07, 2002 4:06 PM
> > > >Subject: Re: How to specify the location of a properties file.
> > > >
> > > >
> > > > >
> > > > > Shaun --
> > > > >
> > > > > Consider dynamically loading the properties file from your classpath
> > > using
> > > > > a class loader. This way, you can put the files anywhere you please
> > > and
> > > > > just include that directory in your classpath (or put them someplace
> > > > > already in your classpath). If you need more specifics, let me know
> > > and
> > > > > I'd be happy to help...
> > > > >
> > > > > justin
> > > > >
> > > > > At 01:00 PM 10/7/2002, you wrote:
> > > > > >I've got a servlet running under Tomcat and I need to read in the
> > > >contents
> > > > > >of a properties file. There will be different properties files for
> > > each
> > > > > >system specified using an init parameter.
> > > > > >
> > > > > >I'm having problems reading this property file at the moment in my
> > > java
> > > > > >class as the way I am doing it at the moment always looks where I
> > > started
> > > > > >Tomcat from i.e the /bin directory. I can specify a full path to
> > the
> > > >file
> > > > > >but this is not very system independent and limits me to either
> > > Windows
> > > >or
> > > > > >Unix.
> > > > > >
> > > > > >What I need is to specify the location of the file relative to the
> > > webapp
> > > > > >directory. I have tried the url class but it doesn't seem to work,
> > or
> > > > > >maybe it is working but looking in a different place to where my
> > > > > >properties file is.
> > > > > >
> > > > > >Can anyone suggest what I am doing wrong or provide any help on the
> > > use
> > > >of
> > > > > >urls in Tomcat?
> > > > > >
> > > > > >Thanks
> > > > > >
> > > > > >
> > > > > >Shaun
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > To unsubscribe, e-mail:
> > > ><mailto:[EMAIL PROTECTED]>
> > > > > For additional commands, e-mail:
> > > ><mailto:[EMAIL PROTECTED]>
> > > > >
> > > >
> > > >
> > > >--
> > > >To unsubscribe, e-mail: <
> > > mailto:[EMAIL PROTECTED]>
> > > >For additional commands, e-mail: <
> > > mailto:[EMAIL PROTECTED]>
> > >
> > >
> > > --
> > > To unsubscribe, e-mail: <
> > > mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail: <
> > > mailto:[EMAIL PROTECTED]>
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail: <
> > mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail: <
> > mailto:[EMAIL PROTECTED]>
> > >
> >
> >
> >
> > --
> > To unsubscribe, e-mail: <
> > mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: <
> > mailto:[EMAIL PROTECTED]>
> >
> >
> >
> >
> >
> >
> > --
> > To unsubscribe,
> e-mail: <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> >
>
>
>
>--
>To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>