• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help me with specify properties file please

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you really want to know where your root directory is located, try new File("").getAbsolutePath().
@+
Ivan
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brown's code helped me worked out. Thanks so much
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic