views:

726

answers:

3

In a servlet I do the following:

  Context context = new InitialContext();
  value = (String) context.lookup("java:comp/env/propertyName");

On an Apache Geronimo instance (WAS CE 2.1) how do i associate a value with the key propertyName?

In Websphere AS 6 i can configure these properties for JNDI lookup under the "Name Space Bindings" page in the management console, but for the life of me I can find no way to do this in community edition on the web.

+1  A: 

One possibility is to add the properties to your web.xml file (in the WEB-INF directory), using one or more <env-entry> tags. For example, something like the following:

<env-entry>
   <description>My string property</descriptor>
   <env-entry-name>propertyName</env-entry-name>
   <env-entry-type>java.lang.String</env-entry-type>
   <env-entry-value>Your string goes here</env-entry-value>
</env-entry>

Each env-entry tag declares a new environment variable that you can then access from the java:comp/env context.

Once you add the necessary env-entry's you can use code similar to what you already posted to access these values. Mind you, I don't have Geronimo installed, so I don't know if there is any additional configuration that needs to be done in order to make this work.

Mike Spross
A: 

@Mike

Thanks for the input, but I am trying to keep the configuration values seperate from the deployed application.

By managing the values at the server level I will then be able to deploy the same .war/.ear to my dev/test/production instances and allow the server to determine such things as where to look for web service endpoints.

stjohnroe
I was wondering myself how to define the values outside of the .war file, but yeah, the Geronimo documentation I found wasn't very helpful. I was hoping someone smarter would provide a more complete answer ;-)
Mike Spross
@MikeSame here, documentation seems to be a bit rubbish as far as this is concerned. I am starting tohave silly ideas like deploying a jndi editor of my ow and seeing if i can get the server to pesrist the values that I enter.
stjohnroe
A: 

Did you ever find an answer to this? I'm trying to do the same thing in the web.xml seems to be the only solution.

Nope, A colleague put a call in with the CE team about a month ago and no response. I am considering setting up a management web-app but i fear that values would not be persisted between restart or would possibly be read only anyway from the app context. Of coures Geronimo is open source.
stjohnroe