Okay gentlemen, I dug around and couldn't find anything on this concept of defining an env-entry after deployment using Sun Java System Application Server 8.1 - so I just came up with my own hack. Thought I'd share it in case others have the same question and can't find the answer.
Just to restate the problem: In SJAS you can't seem to define an environment entry that you can just look up via JNDI (you can do this in Tomcat pretty easy though using the context.xml file and an env-entry like syntax) - the benefit of this being of course that you can easily define deployment-time variables which a system administrator can set based on his setup. There seems to be no way to do this is SJAS 8.1
As a workaround, you can create your own custom JNDI resource which will expose the properties that you set in the Admin Console as a simple java.util.Map that you can use from your app.
Here's the blow by blow:
2. Create a JNDIProperties object that implements java.util.Map but does NOT implement java.io.Serializable:
package helpers.jndi;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public final class JNDIProperties implements Map {
private Map map;
public JNDIProperties(Map aMap) { map = aMap; }
public boolean containsKey(Object key) { return map.containsKey(key); }
public void clear() { map.clear(); }
public Object get(Object key) { return map.get(key); }
public boolean containsValue(Object value) { return map.containsValue(value); }
public Set entrySet() { return map.entrySet(); }
public boolean isEmpty() { return map.isEmpty(); }
public Set keySet() { return map.keySet(); }
public Object put(Object key, Object value) { return map.put(key, value); }
public void putAll(Map t) { map.putAll(t); }
public Object remove(Object key) { return map.remove(key); }
public int size() { return map.size(); }
public Collection values() { return map.values(); }
}
2. Create an object that implements javax.naming.spi.ObjectFactory and returns an instance of JNDIProperties containing the properties defined in the container:
package helpers.jndi;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Map;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
public class PropertyFactory implements ObjectFactory {
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
Map myMap = new Hashtable();
Reference myReference = (Reference)obj;
Enumeration myEnumeration = myReference.getAll();
while (myEnumeration.hasMoreElements()) {
RefAddr myRefAddr = (RefAddr)myEnumeration.nextElement();
myMap.put(myRefAddr.getType(), myRefAddr.getContent());
}
JNDIProperties myJNDIProperties = new JNDIProperties(myMap);
return myJNDIProperties;
}
}
3. Build this and copy the jar to $SJAS_HOME/domains/domain1/lib/ext/ (or other appropriate folder for your setup), then restart the app server to get to load the jar.
4. Go to the admin console and go to Resources -> JNDI -> Custom Resources -> New. Give it a sensible JNDI name (I'll use "testproperties" in this example), enter java.util.Map as the resource type and the name of your factory class for the "factory class" field, e.g. "helpers.jndi.PropertyFactory". Below that under "Additional Properties", add in each of the properties that you want to expose, for example enter a property named "testproperty1" with the value of "my test".
5. You can now get a java.util.Map that contains the properties that you set for your custom JNDI resource by doing something like the following (example in JSP):
<%
Context myContext = new InitialContext();
Context myEnvContext = (Context)myContext.lookup("java:comp/env");
Map myMap = (Map)myEnvContext.lookup("testproperties");
%>
<%=myMap.get("testproperty1")%>
Output is:
my test
NOTE: If this sounds convoluted - I agree, it is. If anyone's got a better idea, please post it; as I could not find another solution to this seemingly simple problem.