• 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

accessing a .properties file

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an action class\servlet that references a .properties file. I am running the app on a websphere server off of my local pc.

The only way I can get the server to see the properties file is to give it a full path ie:
System.setProperty("OSS_CLIENT_CONFIGURATION","C:\\Documents and Settings\\IBM\\rationalsdp6.0\\APworkspace\\APElapsedTime\\WebContent\\WEB-INF\\source\\com\\corp\\elapsedtimeosds\\resources\\OSSclient.properties");

I tried this but got a could not find error:
System.setProperty("OSS_CLIENT_CONFIGURATION","..\\WebContent\\WEB-INF\\source\\com\\corp\\elapsedtimeosds\\resources\\OSSclient.properties");

Obviously I can't use a local path to the properties file when I deploy the app. Any suggestions on how to setup a properties file so that a servlet can read it off of the server?
 
Nikki Freeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually looking around on the forums, I found this:

http://jaitechwriteups.blogspot.com/2007/01/how-to-read-properties-file-in-web.html

I haven't tried it yet, but I don't see why this would not work?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat's documentation lists a couple ways:
http://wiki.apache.org/tomcat/HowTo#head-45c3314139cb900ddd43dde2ff671532e6e844bc

I'm not familiar enough with Websphere to know if there would be a problem with either of these techniques.
 
Nikki Freeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought that would have worked. The problem is I need the properties inside the properties file set as a system property. This code doesn't work - NullPointException :



Thanks for the response
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you going to tell us where the NPE is being thrown?

I'm guessing this needs a leading slash: config/cargo.properties
 
Nikki Freeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David,

Looks like the properties are being loaded. I need to set the properties in the file as system properties. Here's what I have done so far:

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it still a NullPointerException or is it throwing a SecurityException?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly, if you get a reference to the System properties and update them, then the System properties should be updated. You shouldn't need to write them back.

Starting from first principles though, should you be doing this via a properties file, or should you be setting the System properties on the command line using the JVM -D arguments?

Thirdly, you could read the file from into a new properties instance, then iterate the values and use System.setProperty(...)
 
Nikki Freeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David. As always, you are correct on all of those points.

The last problem I am having is, I have an object that needs a properties file setup as a System property. For example,
System.setProperty("CLIENT_CONFIGURATION","C:\\OSSclient.properties");
This works fine, but obviously isn't portable. I have this properties file in the WebContent directory but I get a file not found error when the object referecnces the property. I tried something like this:
System.setProperty("CLIENT_CONFIGURATION","OSSclient.properties");
but that didn't work. Any ideas?

Also, I am running this off of a WebSphere server, but I don't think that should matter too much.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first is portable if you add -DCLIENT_CONFIGURATION=c:\\OSSclient.properties to the command line starting WebSphere rather than including it in the code
 
reply
    Bookmark Topic Watch Topic
  • New Topic