You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ti...@centrelink.gov.au on 2008/01/16 04:55:52 UTC

Access a config file located outsite j2ee app [SEC=UNOFFICIAL]

Hi I'm wanting to store a config file for my J2ee app, somewhere on a 
tomcat server possibly inside the
conf/ directory so that I can update this config file without having to 
redeploy the j2ee app every time a change is made.
I've been told I can use JNDI to access this file, but I can't seem to 
find any examples or documentation on how I can do this.
I would appreciate any help, or suggestions.

So far I can access the file with this code:
Hashtable env = new Hashtable();
                                 env.put(Context.INITIAL_CONTEXT_FACTORY, 
"com.sun.jndi.fscontext.RefFSContextFactory");
 
                                 try {
                                                 Context ctx = new 
InitialContext(prop);
 
                                                 // look up context for 
name
                                                 
//env.put(Context.PROVIDER_URL, 
"file:C:\\confluence\\confluence-2.5.1-std\\conf");
                                                 File f = 
(File)ctx.lookup("/confluence/confluence-2.5.1-std/conf/test.txt");
                                catch {...}


My problems are:

1. The commented line 
env.put(Context.PROVIDER_URL, 
"file:C:\\confluence\\confluence-2.5.1-std\\conf");

it says in examples that this should set the dir to look in to the conf 
dir but if i change the lookup value to just test.txt it cannot find it.

2. Can I somehow set the context to look into the conf directory of Tomcat 
without hard coding the path, as the path could change or be different on 
different machines??
**********************************************************************
IMPORTANT:  This e-mail is intended for the use of the addressee and may contain information that is confidential, commercially valuable or subject to legal or parliamentary privilege.  If you are not the intended recipient you are notified that any review, re-transmission, disclosure, use or dissemination of this communication is strictly prohibited by several Commonwealth Acts of Parliament.  If you have received this communication in error please notify the sender immediately and delete all copies of this transmission together with any attachments.
**********************************************************************


Re: Access a config file located outsite j2ee app [SEC=UNOFFICIAL]

Posted by David Smith <dn...@cornell.edu>.
I tried using relative paths once.  My experience is relative paths 
won't work as the "current directory" is whatever the working directory 
was on tomcat start.  I had to scrap it as it really wasn't consistent 
enough to be usable.  Something to try might be setting this path using:

(inside the Context element for the webapp)
<Environment name="confPath" value="/path/to/conf/file/or/dir"  
type="java.lang.String" override="false"/>

And then call it up in a webapp using a standard JDNI lookup using 
'java:comp/env/confPath':

Context initCtx = new InitialContext();
String confFilePath = (String) initCtx.lookup("java:comp/env/confPath");
// Open the file using standard java.io methods and the path retrieved 
above here

--David

Caldarale, Charles R wrote:
>> From: timothy.fridey@centrelink.gov.au 
>> [mailto:timothy.fridey@centrelink.gov.au] 
>> Subject: Access a config file located outsite j2ee app 
>> [SEC=UNOFFICIAL]
>>
>> 1. The commented line 
>> env.put(Context.PROVIDER_URL, 
>> "file:C:\\confluence\\confluence-2.5.1-std\\conf");
>>     
>
> Not sure this will work (or even if it's a good idea), but you might try
> a relative path with forward slashes (which is what the JVM uses
> internally anyway):
> "file:../conf"
>
> Since Tomcat's normal working directory is bin - at the same directory
> level as conf - this may work.  
>
>   
>> 2. Can I somehow set the context to look into the conf 
>> directory of Tomcat without hard coding the path
>>     
>
> You could set a context parameter or an environment entry:
> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html%20Context%20
> Parameters
> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html%20Environmen
> t%20Entries
> either in the <Context> element or in WEB-INF/web.xml, again using a
> relative path.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Access a config file located outsite j2ee app [SEC=UNOFFICIAL]

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: timothy.fridey@centrelink.gov.au 
> [mailto:timothy.fridey@centrelink.gov.au] 
> Subject: Access a config file located outsite j2ee app 
> [SEC=UNOFFICIAL]
> 
> 1. The commented line 
> env.put(Context.PROVIDER_URL, 
> "file:C:\\confluence\\confluence-2.5.1-std\\conf");

Not sure this will work (or even if it's a good idea), but you might try
a relative path with forward slashes (which is what the JVM uses
internally anyway):
"file:../conf"

Since Tomcat's normal working directory is bin - at the same directory
level as conf - this may work.  

> 2. Can I somehow set the context to look into the conf 
> directory of Tomcat without hard coding the path

You could set a context parameter or an environment entry:
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html%20Context%20
Parameters
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html%20Environmen
t%20Entries
either in the <Context> element or in WEB-INF/web.xml, again using a
relative path.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org