users@glassfish.java.net

Re: JNDI question

From: <glassfish_at_javadesktop.org>
Date: Wed, 24 Oct 2007 04:05:46 PDT

Ok thanks again!

To summarize (trying not to sound too stupid):

Within an application server (Glassfish) I can only access logical names, for example "java:comp/env/something" if they are declared in a deployment descriptor. If a resource is added through the Glassfish admin console I can only access the resource with its "physical" name", within an application running on the Glassfish server that is.

Code example:
I've added a resource in Glassfish admin console, for example a database connection.

In a regular "utility" class, not an ejb, within my ejb application, running on glassfish I have the following function:

    public static Something getSomething() {
        try {
            InitialContext context = new InitialContext();
            return (Something) context.lookup("java:comp/env/something"); // is not working, only "something" is working
        } catch (Exception e) {
            // If no entry is defined or an error occurred use default
        }
        return new Something(3);
    }

This function is used by session beans. I wanted this lookup in a separate function and not injected because if someone changes the resource in the admin console this function can read the new value without restarting the application. But perhaps there are better solutions...
[Message sent by forum member 'woel' (woel)]

http://forums.java.net/jive/thread.jspa?messageID=241842