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
Requirements- Manorrock Glassfish JNDI extensions library
- Glassfish 1.x+
Put the Manorrock Glassfish JNDI extensions 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 exception) {}
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. If want this library, please contact sales@manorrock.com and we will get it to you. Please send comments, suggestions and any feedback to sales@manorrock.com.
(Glassfish 1)