Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2005

Tip: Looking for answers? Try searching our database.

Where to store application settings

Thread view: 
yzzzzz - 25 Mar 2005 10:45 GMT
Hi,

I have a few settings in my webapp (address of the LDAP server, location
of 2 or 3 files), which are in the source code at the moment. This makes
it difficult to change them (and I have to recompile every time). Where
is the best place to store these kinds of settings? I thought of using a
RessourceBundle, what do you think?

Thanks
Josh - 25 Mar 2005 16:09 GMT
I usually put a properties file someone in the web application then use a
"startup servlet" that loads it.  The startup servlet has an init-param
pointing at the file.  Once I've created the properties file, I put it in an
environment object that is shared by everyone.

   try {

     String propsFile = config.getInitParameter("application.properties");

     if (propsFile != null) {
       Properties properties = new Properties();
       properties.load(context.getResourceAsStream(propsFile));
       Environment.initialize(properties);
     } else {
       throw new Exception("Couldn't find application.properties.");
     }

   } catch (Exception e) {
     logger.error("Couldn't load application properties.", e);
     throw new UnavailableException("Couldn't load application
properties.");
   }

Signature

Josh

> Hi,
>
[quoted text clipped - 5 lines]
>
> Thanks
Brian Munroe - 25 Mar 2005 19:36 GMT
I place mine in the WEB-INF/web.xml deployment descriptor for the web
application.

For example:

in WEB-INF/web.xml (in between the <webapp> </webapp> tag)

<env-entry>
   <env-entry-name>docBase</env-entry-name>
   <env-entry-value>doc1</env-entry-value>
   <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

<env-entry>
   <env-entry-name>docBaseUser</env-entry-name>
   <env-entry-value>munroeb</env-entry-value>
   <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

In the servlet or JavaBean that I need the resources:

Context env = (Context) new InitialContext().lookup("java:comp/env");
String docBase = (String) env.lookup("docBase");
String docBaseUser = (String) env.lookup("docBaseUser");


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.