In the last week I’ve had to deal with configuration management for the J2EE application I’m working at the moment. As you may have guessed, I chose the JNDI path. Since I’ve spent an insane amount of time, i.e. more than 5 minutes ;), googling for a solution, I’m gonna share what I discovered. Actually, it’s quite simple, we just need to instantiate a managed bean. Let’s create a file to define two Create a file named pizza-service.xml in your server deploy directory. For the default configuration it should be $JBOSS_HOME/default/deploy. Filename must end with the suffix “-service”, otherwise JBoss will ignore it.
Insert the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server PUBLIC "-//JBoss//DTD MBean    Service    4.0//EN"
    <mbean code="org.jboss.naming.JNDIBindingServiceMgr" name="jboss.apps:name=pizzeria">
        <attribute name="BindingsConfig" serialDataType="jbxb">
            <jndi:bindings xmlns:xs=""
                xs:schemaLocation="urn:jboss:jndi-binding-service resource:jndi-binding-service_1_0.xsd">
                <jndi:binding name="java:pizzeria/capricciosa">
                    <jndi:value trim="true" type="">
                <jndi:binding name="java:pizzeria/margherita">
                    <jndi:value trim="true" type="">

Once you saved the file, JBoss should reload it automatically.
This is all it takes. If you want to separate the JNDI definitions in multiple files, just change the name attribute of the mbean definition. With this solution you can easily handle multiple configurations for your environments (test, staging etc.)