Discussions

General J2EE: Accessing properties from jboss

  1. Accessing properties from jboss (4 messages)

    Hi, Am using jboss AS, and, I would like to give some configuration values(typically key-value). I have a scenario to access certain key values from a config file, I can do it through Properties class and FileInputStream, but i don want to hardcode path to the config file, I also can do it through ClassLoader.getResourceAsStream ("resource.properties"); But what I am wondering here is if I can configure props using something like jboss.properties,etc, so that props are loaded when jboss starts up, and I can access those props through System.getProperty() Appreciate your help! Thanks

    Threaded Messages (4)

  2. Re: Accessing properties from jboss[ Go to top ]

    There are different ways to achieve this in JBoss AS depending on where you need to access the configuration information. In order to access config files from the web layer, you may specify it in your web.xml using relative paths. For e.g you would access a file app.properties located under \server\default\conf folder using a init param for a startup servlet like: appConfigPath /../../../conf/app.properties Alternatively, you may specify the relative path as an attribute for a MBean that you have written. MBean configuration is in jboss-service.xml
  3. Re: Accessing properties from jboss[ Go to top ]

    I do not want to access the property from a servlet or from an MBean, I should have mentioned that, sorry. My scenario is to get some config values from a property file and use it in a few helper classes that I have written to carry out some general functions, for ex, I want to access a timeout value from the property file in the helper class! how do I achieve this, or which is the right way of doing this thanks
  4. Re: Accessing properties from jboss[ Go to top ]

    See run.conf file that is loaded by JBoss boot up. But It will only solve one problem System.getProperty and it is not a typical properties file. In case you want to load it through classloader as well then you may have to put some research and update the Jboss startup script. Keep the properties file in a jar and put it in Server lib and add some unzipping logic to read it un run.sh script as well.. Happy trying..........
  5. Re: Accessing properties from jboss[ Go to top ]

    I could finally access the props specified in jboss-service.xml through an MBean, initially I had mentioned that I did not want to do it through MBean, but now due to a change, I have to do this, and here is an FYI on how to do it : 1) specify your key-value pairs in jboss-service.xml Ex : <!-- Additional properties required by the environment --> <![CDATA[ Key1=11111 Key2=22222 ..... 2)Now in your management bean, put an @Depends Ex: package com.abc.xyz; // your import statements /** * @author somebody * */ @LocalBinding(...) @Service(...) @Management(...) @Depends("jboss.util:type=Service,name=SystemProperties") public class MBeanClass implements MBeanInterface { ... } 3)Now in your Mbean you can access the props with a System.getProperty() call.