In general
The jConfig MBean lets you configure your configurations inside JBoss. There is also
a method which you can use to reload a configuration manually if the file has changed
and you are not using the auto-reload feature of jConfig1.3.
How to install it
The installation requires a few simple steps.
- Copy the jconfig.jar to the $JBOSS_HOME/lib/ext directory.
- Copy the jconfigmbean.jar to the $JBOSS_HOME/lib/ext directory.
- Put the following lines in the $JBOSS_HOME/conf/jboss/jboss.jcml (or whereever your jboss.jcml is)
<mbean code="org.jconfig.mbean.ConfigHandler" name=":service=Configuration,name=MyConfig"> <attribute name="ResourceName">config.xml</attribute> <attribute name="ConfigurationName">MyConfig</attribute> <attribute name="AutoReload">false</attribute> <attribute name="ReloadIntervall">1000</attribute> </mbean>Copy your config.xml (or whatever name you have chosen for your configuration file) to the
$JBOSS_HOME/conf/jboss directory.
Repeat step (3) and (4) for all the different configurations that you need but do not forget to
specidy a different name and a different file.
That's all. The attributes are explained in the next section.
NOTE:
If you run JBoss together with tomcat then the conf-directory is $JBOSS_HOME/conf/tomcat or if
you use Tomcat4 (catalina) then it is $JBOSS_HOME/conf/catalina
Configuring the MBean
We will now explain the attributes in more detail.
ResourceName
This attribute defines the configuration file. It does not have to be a file. You can also
use "http://www.myserver.com/configs/myconfig.xml
". ConfigurationName
This is the name of your configuration instance. If you choose for example "MyConfig" then you can use the ConfigurationManager in this way:
private static final ConfigurationManager cm = ConfigurationManager.getInstance("MyConfig");
AutoReloadThis flag defines if jConfig should watch the file (or whatever). If it is set to true then jConfig will reload the configuration if the resource has changed.
ReloadIntervall
It defines the time in seconds when jConfig should check if the resource for your configuration has changed.
How to build everything
There is a build.xml included and you have to call ANT to build the entire package. This will compile the source code and then generate the jconfigmbean.jar and the examples
(ServerConfig.jar and the ServerConfigClient.class). NOTE: The ANT_HOME has to be set
correct for this one.
Example
This example is very simple. It is mainly a session bean which keeps an instance of the
configuration named "jConfigTest". There is only one method supported:
public String getProperty(String name,String defaultValue,String category)This call is redirected to the ConfigurationManager. There is also a client which calls this method a few times to get some properties. The main purpose is to show how easy it is to use jConfig in a J2EE application.
Inside the org.jconfig.mbean.ejb package is a session bean and the client is in the
org.jconfig.mbean.client package. To run the example deploy the ServerConfig.jar
in the JBoss deploy directory. You also have to follow the installation steps mentioned
above. Please put the following lines inside the jboss.jcml:
<mbean code="org.jconfig.mbean.ConfigHandler" name=":service=Configuration,name=jConfigTest"> <attribute name="ResourceName">config.xml</attribute> <attribute name="ConfigurationName">jConfigTest</attribute> <attribute name="AutoReload">true</attribute> <attribute name="ReloadIntervall">30</attribute> </mbean>The last step is that you have to copy the config.xml from the resources directory to the
$JBOSS_HOME/conf/jboss directory.
Now you can run the client with "run.bat" or "run.sh". Note that we have set the AutoReload to true. Go to the $JBOSS_HOME/conf/jboss directory and change the config.xml (change the value of the property TestEntry for example), wait for 30 seconds and then run the client again. You will see the new value.
NOTE:
Do not forget to install the jconfig.jar and the jconfigmbean.jar (see above)
NOTE2:
To compile and run the example the J2EEHOME and the JBOSSHOME have to be set!
NOTE3:
Please check the settings in the jndi.properties file so that you set the correct host!