• 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

set env property for the project

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Folks,

Please help me to set the env variable for the whole project.

Some thing like project contains 20 to 30 class files located accross the packages. The variables set should be visible to all the class files.
I tried with:

java.util.Properties prop = new java.util.Properties();
prop.setProperty("one", "NULL");
prop.setProperty("two", "welcome");
prop.setProperty("three", "hello");
System.setProperties(prop);

How to make it visible to all the classes.

Regards,
Arjun
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Place your peoperties in a props file and use methods of ClassLoader or Class to load the properties file on startup.

Read this excellent article to find out more about loading properties.

Thanks,
Ram.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Part of the issue here is where to declare the Properties object. If you declare it local within a particular method, then no one else will be able to access it. Perhaps there is a design pattern that will help solve this problem. Using a Singleton class to encapsulate the project's properties is one idea that comes to mind. If you are unfamiliar with the Singleton design pattern, you should google for it.

Layne
 
Arjun K
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Layne,

Thats a good idea. I do know about the singleton design pattern; which gives same instance on every object creation.

Let me know if there is any thing interesting....

-Arjun.
reply
    Bookmark Topic Watch Topic
  • New Topic