Introduction
Software development generally has production environments and test environments that
each are used for what they are meant for. Most times the test environment and the
production environment are using different resources. While the JavaEE specification
makes it easy to setup different environments for databases it is a bit harder if you
have other resources that are different between environments. This article describes
how you can use the Glassfish JDNI tree and a small JAR file available to the application
server to store environment settings.
Requirements
- Manor 'n Rock Glassfish JNDI library
- Glassfish 1.x+
Setup
Put the Manor 'n Rock Glassfish JNDI library in $GLASSFISH_ROOT/lib.
Create a Custom JNDI resource with the following details:
JNDI name : myapplication/mykey
Resource Type : java.lang.String
Factory Class : com.manorrock.glassfish.jndi.JndiStringFactory
And make sure you also add the following property:
Name : value
Value : myvalue
The following code snippet shows you how you can access this inside your application or
JSP page:
String value = "";
try {
InitialContext context = new InitialContext();
value = (String) context.lookup("myapplication/mykey");
}
catch(NameNotFoundException nameNotFoundException) {}
The code snippet will store the value "myvalue" in the variable value.
You now have the ability to create web applications that are identical between
environments. Please send comments, suggestions and any feedback to mriem@manorrock.org.
If you like this little library please go to the
Manor 'n Rock Glassfish extensions
page for more details.
(Glassfish 9.0+)