I have read that, since Java EE 6, it is possible to programmatically bind values into the java:app:env, java:comp:env and java:global:env. However, when I attempt it, I get a javax.naming.OperationNotSupportedException.
I'm doing this from a startup bean, using Liberty 8.5.5.6. Is the problem Liberty, the way I'm coding, or the premise that you can programmatically bind into these namespaces?
(Simplified) code:
@Startup
@Singleton
public class ConfigStartup {
@PostConstruct
void initialize(){
try {
InitialContext ic = new InitialContext();
ic.bind("java:app:env/LOGGING_LEVEL", "ALL");
} catch (Exception e) {
e.printStackTrace();
}
}
}
The Liberty profile does not support write operations to the java:
namespace. The EE 7 platform specification never mentions write operations for the java:
namespace (but often discusses applications declaring resources that the application server should allow applications to read), and the EE compliance test suite apparently does not require write operations, so I think it's quite reasonable for an implementation to disallow them.
If this capability is important to you, you could open a WebSphere RFE, but I would recommend finding an alternative solution. For example, you're already using a singleton session bean, so you could just store the data in a member variable and have consuming code look up the singleton session bean's java:global
JNDI name and call a getter method.