Skip to main content

context.xml - problem obtaining

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
gernot1
Offline
Joined: 2009-04-18

I've put META-INF/context.xml in my WAR, with following content

<Context>
<Environment    name="data-directory" value="/some/path" type="java.lang.String"/>
</Context>

In tomcat I used
        Context initContext = new InitialContext();
        Context envContext = (Context) initContext.lookup("java:/comp/env");
        String dataDir = (String)envContext.lookup("data-directory");

to obtain "data-directory".
But how is this done in Glassfish?
I tried above code, and following:
            Context initContext = new InitialContext();
            tring dataDir = (String)initContext.lookup("data-directory");

but I always got a NamingException ("Lookup failed").
Any suggestions?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gernot1
Offline
Joined: 2009-04-18

There was an unnecessary "/" which causes the error. Using

 initContext.lookup("java:comp/env");

and it works!