• 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

properties file in websphere

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have used properties files in the past for specifying values that may change in java code. I would like to add a properties file for a JavaBean to reference. My questions are related to file placement of this properties file. I'm using WSAD 4.0.3 on Windows 2000. Where do I put the properties file in WSAD so that my code will compile? Next, where does this properties file go when I deploy my project to WAS 4.0.3 on AIX?
I would really like to use a properties file so that I can easily switch between our development database and our production database. If anyone could help me out, I'd really appreciate it!
Thanks.
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone address this issue please? I've searched on JavaRanch and google, and haven't been able to find a solution.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
could u pl specify whether u r using the properties file from a servlet in a war file or from a EJB in a jar file.
if servlet u can specify the path in the init parameter and read it within ur servlet. or u can load it using
InputStream is = getClass().getResourceAsStream("/rollout.properties");
Properties props = new Properties();
try
{
props.load(is);
}
catch (Exception e){}

if u want to load the properties file with in ur EJB then u can make use of the Environment variables.
hope this helps.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easiest solution would be to use a ResourceBundle (specifically PropertiesResourceBundle) ..... place your properties file say sampleConfig.properties under ejbModule (for EJB Projects) or source directory for a Web project. Now in ur class file you need to have something like this ...
ResourceBundle bundle = ResourceBundle.getBundle("sampleConfig.properties");
....
String value1 = (String)bundle.getObject("Key1");
.....
Hope this helps.
PJ
[ July 30, 2002: Message edited by: Prashanth Joisha ]
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For WSAD, I think you just attach the .properties file to your project as a resource.
For WAS, the .properties file goes into your 'Document Root', which is a directory you specify per web application. You find the setting for this in the properties for the web application.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I fully agreed with this solution .Only thing I want to add is that while using ResourceBundle the baseclass(Property file) must be fully qualified (for example, myPackage.sampleConfig, not just sampleConfig).
Regards
Seema Verma

Originally posted by Prashanth Joisha:
The easiest solution would be to use a ResourceBundle (specifically PropertiesResourceBundle) ..... place your properties file say sampleConfig.properties under ejbModule (for EJB Projects) or source directory for a Web project. Now in ur class file you need to have something like this ...
ResourceBundle bundle = ResourceBundle.getBundle("sampleConfig.properties");
....
String value1 = (String)bundle.getObject("Key1");
.....
Hope this helps.
PJ
[ July 30, 2002: Message edited by: Prashanth Joisha ]

 
pjoisha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from a coding perspective - I don't think so.
PJ
[ August 06, 2002: Message edited by: Prashanth Joisha ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am putting .properties file in WEB-INF/classes
and using ResourceBundle to extract the values,it works fine ,Is there any thumb rule that specifies that property files should be here or there?
 
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 problem with this is that the properties will be unavailable on the EJB layer, so you have to either replicate the properties (evil) or find somewhere else to put it.
Of course it isn't so much of a problem if you don't have EJBs or they don't have to share properties.
Dave
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In WSAD, you have more flexibility in where you can place your file. For example, I can place the file under the web application directory and reference it. The problem is when you deploy outside of WSAD. My recommendation is to put it into your source directory. It will then show up in your WEB-INF/class directory.
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Folks,
You can always set the working directory of the application server and then pick up the properties file relative to the working directory. This allows EJBs and Web apps to access the same properties files.
I hope helps.
Cheers,
Steve
 
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
This is the way we currently do it, but it only really works if everything runs on the same machine (or if all machines share the same file system, which is just as bad) - it isn't compatable with a distributed application.
We're currently in the process of evaluating our use of properties (on Websphere) to come up with 'something better', but asn efficient solution to the distributed thing is a bit of a poser.
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
If you are looking for a single repository for properties in a distributed environment you should probably be looking towards either a directory service such as LDAP or using a database to store the information.
The problem with only having one place for all the properties for all the servers is that you introduce a further single point of failure! If the database/directory service fails then all your servers are likely to suffer unless they cache the properties at startup - though they could still experience problems if you need to restart the servers.
You need to weigh up whether you require redundancy and failover or this single repository.
Cheers,
Steve
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
I've tried some of your responses. Here's our scenario: we're using JSP and servlets on WAS 403 running on AIX, with Apache 1.3.20 Web Server. We're using only one app server. The JSP and servlets access JavaBeans. We're not using EJB's. The JavaBeans then need to create a connection with the database. My purpose of using the properties file is for an easy way to switch between our production and development databases. We have different database names and usernames and passwords for prod and dev. Therefore, I would like an easy way to change these values without having to modify the constants in the JavaBean. That said, here is how I'm trying to use the properties file:
I have created a properties file called test.properties with the following data:

I then have this code in my JavaBean:

I have tried specifying the full path to the properties file; however this doesn't work either. The message in the log is:

I have the properties file in /usr/apps/WebSphere/AppServer/installedApps/test-dev.ear/test.war/WEB-INF/classes/test directory. The test directory at the end is also where the class file for my JavaBean resides.
Can someone please tell me how I should be referring to the properties file? I'm not sure if the problem is how I'm referring to it or where I'm putting the file. The properties file has full permissions (777).
Any direction on this issue is greatly appreciated!!
[ August 12, 2002: Message edited by: verduka fox ]
 
pjoisha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try putting your properties file in the classes dir ..... ie WEB-INF\classes dir
PJ
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I got it working. I had to change the following line:
bundle = (PropertyResourceBundle)PropertyResourceBundle.getBundle("test.properties");
to:
bundle = (PropertyResourceBundle)PropertyResourceBundle.getBundle("com.mycompany.myproject.test");
Now it seems to work. One last question: when I change values in the properties file, should I have to stop and start the app server for these changes to be recognized? I didn't think I would need to, but from my testing it seems as though this is required. Can anyone comment on this?
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing: my manager asked me to check if using the properties file creates any security holes, ie is anyone able to access this file through the browser? This would be crucial to know: if this is the case, we cannot use the properties file. I have the properties file in my WEB-INF/classes/... folder. Please respond.
[ August 12, 2002: Message edited by: verduka fox ]
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone comment on my two final issues with using the properties file please:
1) When I change values in the properties file, should I have to stop and start the app server for these changes to be recognized? I didn't think I would need to, but from my testing it seems as though this is required. Should this be the case?
2) Does using the properties file create any security holes, ie is anyone able to access this file through the browser? If this is the case, we cannot use the properties file as the intruder would then find the database name, username and password. I have the properties file in my WEB-INF/classes/... folder. Please let me know if this is a problem.
Your expertise in this area is really appreciated!
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry to ask again, but I still haven't found the answer to my questions:
Can anyone comment on my two final issues with using the properties file please:
1) When I change values in the properties file, should I have to stop and start the app server for these changes to be recognized? I didn't think I would need to, but from my testing it seems as though this is required. Should this be the case?
2) Does using the properties file create any security holes, ie is anyone able to access this file through the browser? If this is the case, we cannot use the properties file as the intruder would then find the database name, username and password. I have the properties file in my WEB-INF/classes/... folder. Please let me know if this is a problem.
Your expertise in this area is really appreciated!
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for [2], to hide your properties you could add a jar file, say properties.jar that you put in adminserver.bat or setupCmdLine.bat. This will be found by your classloaders. At worst you can put this jar in /lib/app (assuming 4.x and above)
As for [1] how do you obtain your properties? Do you use ResourceBundle.java or do you use getSystemResourceAsStream? If you use the former, then you have to bounce your adminserver (90% sure). If you use the latter, I don't know, I would guess that it should be read from the classpath each time.
-t
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just place the properties file in your class path, and use a class loader to gain access to it. Every time that you change your properties file you will have to restart your web container.
Also, if you read Sun's java spec, you will see that files in the WEB-INF directory are not accessible.
BTW - the WSAD 4.1 version is a little less buggy than 4.0.3.
I've found that certain key stroke combinations in 4.0.3 brings it down.
I typically create a resource servlet that bootstraps at load time of the servlet container. The resource servlet then gives access to the properties fields. I usually define an init parameter to my resource servlet in the web.xml file. This init parameter is the name of the properties file that I want to gain access to.
Then if you place the file in the same location in your sources directory in WSAD as your servlet, you can use the following code snippet.
String dataSource = getInitParameter("dataSource");
URL configURL = getServletContext.getResource(dataSource);
Properties props = new Properties();
props.load(configURL.openStream());
If you want to pass the properties to an ejb container, make sure your method signature to the ejb contains an environment variable. This environment variable should be a hashtable (or HashMap) containing all your needed properties by the ejb layer.
[ August 24, 2002: Message edited by: Ron Ditch ]
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I am facign what is a familiar situation: I recently deployed Log$J in our project which takes a Property file as an argument. Under WSAD 4.03 I put the property file in the Application Developer directory and this works. When we try to deploy on AIX, however (WAS) we get a ‘Logger (the name of the wrapper class which wraps Log4J) violates loader constraint’.
The properties file is in the applications root directory along with the supporting jars.
Any ideas?
thanks
 
All of the following truths are shameless lies. But what about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic