You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Peter Menzel <pe...@imise.uni-leipzig.de> on 2005/10/14 13:25:42 UTC

Accessing Environment Entries from LifecycleListener

Hi there,

I have configured a global environment entry and a lifecycle listener in 
server.xml:
<GlobalNamingResources>
    <Environment name="myvar" type="java.lang.String"  value="myvalue"/>
[..]
</GlobalNamingResources>

<Listener className="my.listener.TomcatListener"/>

The listener implements LifecycleListener and works fine.
Now I want to access the envionment entries in this listener by:

public void lifecycleEvent(LifecycleEvent event) {
        if (event.getType().equals(Lifecycle.AFTER_START_EVENT)) {
            try {
                  Context ctx = (Context) new 
InitialContext().lookup("java:comp/env");
                  String myval = (String) ctx.lookup("myvar");
            } catch (NamingException ne) {
                  System.out.println(ne.getMessage()+ne.getExplanation());
            }
    [...]

Unfortunately this won't work and an exception is thrown:
"Name java:comp is not bound in this ContextName"

Is it genreally possible to access environment entries from within 
LifecycleListener ?

Regards, Peter Menzel


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