• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing a .properties file

 
Nikki Freeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic