• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

relative path for .properties file .. pls help

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I am using Tomcat 4.1 with J2SDK 1.3.1_08. I have setup a context in
C:\1LMS\web-app
The LoadProperties.java file is located in:
C:/1LMS/web-app/WEB-INF/classes
and file.properties in
C:/1LMS/web-app/WEB-INF/classes/file.properties
My question is, how could I put the file.properties into say /WEB-INF/config
without having to specify the fullpath ('coz the instance name could change).
final String configFile= "../config/file.properties";
does not seems to work.
Thank you.

-------LoadProperties.java----------------
import java.util.*;
import java.io.*;

public class LoadProperties {
static void displayValue() {
final String configFile = "C:/1LMS/web-app/WEB-INF/classes/file.properties";
Properties Prop = new Properties();
try {
FileInputStream configStream = new FileInputStream(configFile);
Prop.load(configStream);
configStream.close();
} catch(IOException e) {
System.out.println("Error: Cannot laod configuration file ");
}
final String PathImage =Prop.getProperty("ImagePath");
final String PathJsp = Prop.getProperty("JspPath");
System.out.println("ImagePath = " + PathImage);
System.out.println("JspPath = " + PathJsp);

} // displayValue

static public void main(String[] args) {
displayValue();
} // main
} // class
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there are two solutions.
1. if you are using a servlet you can use

2. get the path via the classloader

where the starting point is the classes directory in the Web-Inf folder
 
Chuan Ren
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. That works.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic