users@glassfish.java.net

Re: Get application context root through JNDI

From: Harald Wellmann <hwellmann.de_at_gmail.com>
Date: Sun, 02 Dec 2012 17:45:58 +0100

Have you tried the following names defined in the Servlet 3.0 specification:

     15.2.3 JNDI Name for Web Module Context Root URL

     The name of the pre-defined java.net.URL resource for the context
root of a web application has the following syntax:


     java:global[/<app-name>]/<module-name>!ROOT in the global namespace
     and

     java:app/<module-name>!ROOT in the application-specific namespace.

Best regards,
Harald

Am 01.12.2012 16:17, schrieb forums_at_java.net:
> Hi, Is there a way to get the context-root of the currently running
> application at runtime? The name of the application is no problem: String
> appName = (String)InitialContext.doLookup("java:app/AppName") Likewise, I
> tried: String appContextRoot =
> (String)InitialContext.doLookup("java:app/ContextRoot") but no dice. When I
> look at the application details in the admin panel, I see a number of
> "properties":
> Name Status Virtual server Context root Description Location Libraries
> Modules
>
> I would expect that all these properties can be queried, but so far I only
> succeeded in getting the Name of the application. Is it possible to get to
> the others as well? I need to retrieve the context-root from a static
> method,
> so I cannot use HttpRequest. Cheers, sohan Glassfish 3.1.2 JDK 1.7
>
> --
>
> [Message sent by forum member 'sohan']
>
> View Post: http://forums.java.net/node/892853
>
>