wood burning stoves*
The moose likes Servlets and the fly likes help me with specify properties file please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "help me with specify properties file please" Watch "help me with specify properties file please" New topic
Author

help me with specify properties file please

Danny Tran
Greenhorn

Joined: Mar 02, 2003
Posts: 8
hi,
I have a properties file "application.properties" and i put it in config directory from the application root (web-inf/classes/config/application.properties) and deploy the application in weblogic 7.0.2
in the same directory (config) i have a Configurator class (Congurator.class) that tries to read this file. however i could not figure out how to specify the path for the properties file
currently i have:
properties.load(new FileInputStream("/config/application.properties"));
but this returns FileNotFoundException. i tried with other path ("application.properties") but it return the same exception.
if anyone know how to fix this, please help me.. this one really drives me crazy =(
many thanks.
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Danny
One question must be needed to answer, which computer platform/Operating system are you now using?
Is it UNIX platform?
Please reply


Francis Siu
SCJP, MCDBA
Danny Tran
Greenhorn

Joined: Mar 02, 2003
Posts: 8
hi, thanks for replying, I am using Winxp, weblogic7.0.2 and my .war is in(C:\Bea\user_projects\scm\scm.war)
danny.
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
Ar...
According to your coding
properties.load(new FileInputStream("/config/application.properties"));
Did you try use full path instead of use '/'
If I predict correct,using '/' is in Unix platform.
If full path can not work, I suggest you can use JFileChooser which can pop up a menu that you can choose whatever file you want.
Hope this help
Danny Tran
Greenhorn

Joined: Mar 02, 2003
Posts: 8
hi, i actually want to use a relative path from my application root that is deployed into weblogic i.e. c:\bea\user_projects\scm\scm.war
i mean a web application packaged in war file should have
WEB-INF (dir)
web.xml
and my application.properties is in
WEB-INF/classes/config/application.properties
how can i reference to the application-root not the os root. can u help!
danny.
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
Danny
I am sorry that I use a lot of time to find out some information about related to your problem,but eventually,I can not find out the solution.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
You have a couple of options with web applications. First of all you use the ClassLoader to load the resource, or you can load the resuorce relative to the web application root using the ServletContext.
Example 1 : Say you have a file called my.properties sitting in the WEB-INF/classes directory, you can use the following snippet to get an InputStream to that file.

Example 2 : Say you have a file called my.properties sitting underneath the WEB-INF directory.
In this case, you can load the file using the following snippet (assuming you have access to a ServletContext instance)

Hope that helps!
Simon
Ivan Matmati
Ranch Hand

Joined: Feb 26, 2003
Posts: 41
If you really want to know where your root directory is located, try new File("").getAbsolutePath().
@+
Ivan


No Gates!<p>SCPJ 1.4<br />SCWCD 1.4
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
No, new File("") will be what the JVM thinks is the "current" directory, not the root of your web application. In a servlet environment you have no control over the "current" directory.
Murali Nanchala
Ranch Hand

Joined: Mar 14, 2001
Posts: 74
Check out java.util.ResourceBundle Class to get the properties in the appserver classpath.
Or else, just dump them into the domain directory instead of the WAR file. They will be available for configuration between Server restarts and without having to build the WAR again. Your domain directory is your classpath root.
Ex: C:\bea\user_projects\yourDomain


"It is almost always answered in the API" - Murali Nanchala
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
Another option would be to put a -D flag on the line that starts the webLogic server that gives a name and location for the properties file. Then you can access that system property
java -DPROPERTY_FILE=c:\bea\..\file.properties
then use System.getProperty("PROPERTY_FILE") to retrieve the path
Brian
Danny Tran
Greenhorn

Joined: Mar 02, 2003
Posts: 8
Brown's code helped me worked out. Thanks so much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help me with specify properties file please
 
Similar Threads
unusual exception with properties file path --- please help
multiple message resource file for multiple struts-config.xml
referencing folders from within build.xml
Exception with specifying properties file path in application
FileNotFoundException with specifying Properties file