> Can I specify the DB parameters in a jndi.properties file that my
standalone
> app accesses, just like Tomcat's server.xml specifies Resources and
> ResourceParams? (i.e. maxActive, maxIdle, url, etc in a
jndi.properties
> file).
>

Details would depend on which JNDI provider you use, and how it's
configured.  But you'll definitely need to do some sort of external
configuration.

> If we CAN specify such properties and access them throughout the
webapp,
> what is the point of specifying them in Tomcat's server.xml file?  I
ask
> because if we need JNDI lookup of a DataSource in Tomcat you have to
> manually configure the server.xml file to use it.  This goes against
the
> principle of packaging things in a nice self-contained .war file and
having
> the application work just by dropping it in to the webapp directory
(that
> is, there should be no external configuration necessary outside of
the war
> context).
>

My main goal now is to create an InitialContext through a
jndi.properties file. I am new to jndi and I don't know how to best
approach the task. I'm trying to create a simple login that relies on a
connection pool. 

I, like  Les Hazlewood, wish to use a distributable, reusable component
that does not rely on server.xml configuration.

I have posted my code on Tomcat-user forum, but it got ignored there.
This forum, especially this thread, is closer to my goals.

Here's my broken code: (you can see I am really lost here)


        public void init() throws Exception {
                        
                if (ds != null) return;
                        
                ResourceBundle SQL = ResourceBundle.getBundle("jndi");

                Hashtable env = new Hashtable(9);

        
                env.put(Context.INITIAL_CONTEXT_FACTORY, this);
                env.put(Context.PROVIDER_URL, SQL.getString("factory"));
                env.put(Context.SECURITY_AUTHENTICATION, SQL.getString("username"));
                env.put(Context.SECURITY_CREDENTIALS, SQL.getString("password"));
                env.put(Context.PROVIDER_URL, SQL.getString("url"));
                
                Context ctx = new InitialContext(env);
                
                ctx.addToEnvironment("driverClassName",
SQL.getString("driverClassName"));
                ctx.addToEnvironment("maxActive", SQL.getString("maxActive"));
                ctx.addToEnvironment("maxIdle", SQL.getString("maxIdle"));
                ctx.addToEnvironment("maxWait", SQL.getString("maxWait"));
                
                if(ctx == null) 
                        throw new Exception("No Context");

                String CONTEXT_LOOKUP_ADDRESS = SQL.getString("context.lookup");
                try{
                        
                        ds = (DataSource)ctx.lookup("java:comp/env/jdbc/WebPool");
                }
                catch(Exception e){
                        throw new Exception("Context Address invalid: "
                                                                + 
CONTEXT_LOOKUP_ADDRESS+" "+ e.toString());
                }
        }



=====
Garrett Smith
http://dhtmlkitchen.com/

__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to