My first inclination was to try to do this with a JNDI Environment Entry, so I began researching that approach. However, while the EJB spec states that the container must “provide a deployment tool that allows the Deployer to set and modify the values of the enterprise bean’s environment entries” (thanks for finding that one, ipage), JBoss does not seem to have such a facility.
Soon I started to wonder if JNDI wasn’t a bit overkill for what I needed to do, anyway. I didn’t want to specify my parameters on the command-line; I wanted to simplify deployment and wanted to be able to change these values at runtime without restarting the server. But perhaps a System Property was all I needed.
As it turns out, JBoss has the System Properties Management Service for such things. Here’s what you need to do:
- Make sure properties-plugin.jar is in your ${JBOSS_HOME}/server/
/lib directory. - Make sure the properties-service.xml is in your deploy directory (you can find a copy in the “default” server directory)
- You now have two options, either edit the URLList to have a comma-separated list of locations of properties files, or you can specify your properties directly in properties-service.xml in the
element.
Now, to access your property, all you need to do is call the venerable System.getProperty() method.