views:

290

answers:

3

I usually use Commons Configuration for manage my applications configs. I have used properties files configuration. Now I'm interested in using a JNDIConfiguration but I'm not able to understand how this works reading the documentation or googling it.

Contextualizing, I'm working in webapps running in an JBoss AS.

Where will be the properties stored? In a file? some tables in a database?

I will be grateful for any guidance at this level even if it comes in shape of links where I can read some valuable information about it.

As a final note my goal is to free me of linking a file with a hardcoded path for my properties, but also don't force me to have my config in database tables. If you have any suggestions on how to do that in some other way be free to share.

+1  A: 

I don't know much about Commons Configuration and JNDIConfiguration, but if what you want is a set of key/value pairs, the standard way of doing this as per the JEE specs, is to use env-entry in the web.xml or ejb.xml.

<env-entry>
  <env-entry-name>maxExemptions</env-entry-name>
  <env-entry-value>10</env-entry-value>
  <env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>

(example taken from JBoss web conf. reference.)

These values are bound in the JNDI so they can be looked up or injected.

ewernli
thank you ewernli, this will be useful!, however it's not what i'm looking for this specific concern.
rsilva
+1  A: 

JNDIConfiguration looks up the configuration data on a JNDI server (in your case, the JBoss JNDI server). However, you still need a way of getting that data into the JNDI server in the first place, and Commons-Configuration won't help you with that.

It sounds to me that JNDI isn't what you want, it's just pushing the problem around a bit. JBoss still needs to store the configuration data somewhere, so you'll still have the same basic problem.

If you don't want hard-coded file paths, and you don't want a database, then I suggest you pass in the location of the properties file via a system property, e.g.

java -Dmy.config.path=/my/config.properties com.MyClass

Then pass that location to Commons Configuration and let it load your config that way. No hardcoded-paths, no database.

skaffman
"....you still need a way of getting that data into the JNDI server..." - This it's my main question! how to do that? In my case and don't have to concern with an hard coded path in the JNDI server because it is environment dependent and not application dependent, meaning when I'm packaging my app who uses it don't have to place the configuration in some path I decided but can use wherever he/she wanted.
rsilva
Getting stuff in and out of the JNDI server requires a JNDI editor tool. I'm not aware of one that ships with JBoss, but such things must exist somewhere.
skaffman
+1  A: 

Where will be the properties stored? In a file? some tables in a database?

As @ewernli mentioned, the JEE way to add entries in the JNDI tree is to use env-entry in your deployment descriptor(s).

Now, if you don't want to repeat the same env-entry in several deployment descriptors, then there is a service for specifying global JNDI bindings: JNDIBindingServiceMgr.

Below, the provided jboss-service.xml example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
          "http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd"&gt;
<server>
   <mbean code="org.jboss.naming.JNDIBindingServiceMgr"
         name="jboss.tests:service=JNDIBindingServiceMgr">
      <attribute name="BindingsConfig" serialDataType="jbxb">
         <jndi:bindings
            xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
            xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd"
            >
            <jndi:binding name="urls/jboss-home">
               <jndi:value type="java.net.URL">http://www.jboss.org&lt;/jndi:value&gt;
            </jndi:binding>

            <jndi:binding name="hosts/localhost">
               <jndi:value editor="org.jboss.util.propertyeditor.InetAddressEditor">
                  127.0.0.1
               </jndi:value>
            </jndi:binding>

            <jndi:binding name="maps/testProps">
               <java:properties xmlns:java="urn:jboss:java-properties"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
                  xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
                  <java:property>
                     <java:key>key1</java:key>
                     <java:value>value1</java:value>
                  </java:property>
                  <java:property>
                     <java:key>key2</java:key>
                     <java:value>value2</java:value>
                  </java:property>
               </java:properties>               
            </jndi:binding>
         </jndi:bindings>
      </attribute>
      <depends>jboss:service=Naming</depends>
   </mbean>

</server>

If this is not what you are looking for, then I don't understand what you're looking for :) In that case, you should maybe clarify it.

Pascal Thivent
it's exactly that! Thank you so much!
rsilva