File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help me with specify properties file please

 
Danny Tran
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 867
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Danny
One question must be needed to answer, which computer platform/Operating system are you now using?
Is it UNIX platform?
Please reply
 
Danny Tran
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 867
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 867
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1913
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really want to know where your root directory is located, try new File("").getAbsolutePath().
@+
Ivan
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Brian Nice
Ranch Hand
Posts: 195
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brown's code helped me worked out. Thanks so much
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic