You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sebastian Stein <se...@hpfsc.de> on 2005/12/08 22:45:15 UTC

Handling config files

Hi,

I have a config file in WEB-INF/classes/ directory. This file has the
information for database connection. How can I make this file accessible in
all Action classes? I guess there must be a unified way to access such a
file.


Sebastian

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Handling config files

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
No, believe it or not, there's no standard way of doing this.

One option is here:

http://javawebparts.sourceforge.net/javadocs/javawebparts/listener/AppConfigContextListener.html

...which is part of Java Web Parts:

http://javawebparts.sourceforge.net

This is a ContextListener which makes it easy to get your config file 
into an object you can use later.

Frank

Sebastian Stein wrote:
> Hi,
> 
> I have a config file in WEB-INF/classes/ directory. This file has the
> information for database connection. How can I make this file accessible in
> all Action classes? I guess there must be a unified way to access such a
> file.
> 
> 
> Sebastian
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Handling config files

Posted by gr...@intellicare.com.
Sebastian Stein <se...@hpfsc.de> wrote on 12/08/2005 05:31:36 PM:

> gramani@intellicare.com <gr...@intellicare.com> [051208 23:27]:
> > String xpdlPropertiesFileName = "xpdl.properties"; //file should be in 
the 
> > class path..
> 
> Sorry for the stupid question, but what are possible class paths in a
> webapp? I guess it is the WEB-INF/lib directory, but any other 
directory?

I believe it is WEB-INF/classes that is the "default" class path for the 
web app. Of course you could put the file anywhere and then write the path 
to the file as a context-wide parameter in your web.xml. The reason I 
didn't like this is I had to change it when we moved from dev to prod - 
and I always ended up forgetting. I later changed my ant build file so my 
prod war had the correct version, but finally I just preferred the simple 
solution of putting it under WEB-INF/classes..:)

> Sebastian

Regards,
Geeta

Re: Handling config files

Posted by Sebastian Stein <se...@hpfsc.de>.
gramani@intellicare.com <gr...@intellicare.com> [051208 23:27]:
> String xpdlPropertiesFileName = "xpdl.properties"; //file should be in the 
> class path..

Sorry for the stupid question, but what are possible class paths in a
webapp? I guess it is the WEB-INF/lib directory, but any other directory?
Can this be configured?

Sebastian

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Handling config files

Posted by Sebastian Stein <se...@hpfsc.de>.
gramani@intellicare.com <gr...@intellicare.com> [051208 23:27]:
> There are probably many ways of doing this (I don't know of any "standard" 
> way though). Here's some code which i use to populate a Properties object 
> from a file:
> 
> String xpdlPropertiesFileName = "xpdl.properties"; //file should be in the 
> class path..
> InputStream is = null;
> ClassLoader loader = Thread.currentThread().getContextClassLoader();
> is = loader.getResourceAsStream(xpdlPropertiesFileName);

Thanks, I tried this and it works great!

Sebastian

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Handling config files

Posted by gr...@intellicare.com.
Hi Sebastain,

There are probably many ways of doing this (I don't know of any "standard" 
way though). Here's some code which i use to populate a Properties object 
from a file:

String xpdlPropertiesFileName = "xpdl.properties"; //file should be in the 
class path..
InputStream is = null;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
is = loader.getResourceAsStream(xpdlPropertiesFileName);

//read the properties..
if (!initialized ) {
        if (is != null) {
                processVariables = new Properties();
                processVariables.load(is);
                initialized = true;
        }
        else log.error("Aaaarrgghhh!! xpdl.properties file dne!!!");
}

Regards,
Geeta

Sebastian Stein <se...@hpfsc.de> wrote on 12/08/2005 04:45:15 PM:

> Hi,
> 
> I have a config file in WEB-INF/classes/ directory. This file has the
> information for database connection. How can I make this file accessible 
in
> all Action classes? I guess there must be a unified way to access such a
> file.
> 
> 
> Sebastian
>