I'd like to use a ServletFilter that reads it configuration from the java:comp/env/ JNDI namespace. As the value will be different on devel and production servers, it should not be hardcoded via in web.xml but instead be configured in the application server.
I already tried the following places but none seemed to be right:
- System Properties
- Web Container / General Properties
- JVM Settings / Additional Properties (suggested in How to set an env variable in Glassfish 2.1)
- Resource Connectors (didn't work)
- asenv.conf (only in Glassfish 2?)
How can I set a custom JNDI variable in Glassfish 4.1?
I installed only the Glassfish 4.1 Web Edition. While it has JNDI support, the web GUI comlpetely lacked the Resources -> JNDI menu to configure own variables!
In the Web Profile Glassfish, custom JNDI variables can be written in the domain.xml, they seem to survive other changes via the Admin GUI:
After adding a JNDI variable to Glassfish, it's only availble with InitialContext.doLookup("cas/serverName") though, not within the java:comp/env namespace. To get that, I had to add the following to my web.xml (it did not work in glassfish-web.xml!):