Mike Desjardins is an Enterprise Java developer who lives in Portland, Maine, U.S.A. His primary focus is on ORM technologies, Database Design, and Web Services, as well as occasional dabbling in web design. Mike is also a proud parent and avid gardener. Mike is a DZone MVB and is not an employee of DZone and has posted 6 posts at DZone. You can read more from them at their website. View Full User Profile

External Configuration With JBoss

01.12.2009
| 10286 views |
  • submit to reddit

In a project I’m currently working on, I need to make some parameters configurable, and they need to be outside the .war file that I’m deploying. For example, let’s say I’m creating a service which reads data from some other RESTful service. And let’s say that the other RESTful service has two URLs, one for test and one for production. I’d like to be able to deploy my .war, and then edit a file outside of that .war file to configure which URL my service should be using.

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 in 20.2.4 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:

  1. Make sure properties-plugin.jar is in your ${JBOSS_HOME}/server/<server>/lib directory.
  2. Make sure the properties-service.xml is in your deploy directory (you can find a copy in the “default” server directory)
  3. 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 <attribute name=”Properties”> element.

Now, to access your property, all you need to do is call the venerable System.getProperty() method.

From http://mikedesjardins.us/wordpress

3
Your rating: None Average: 3 (1 vote)
Published at DZone with permission of Mike Desjardins, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Howie Guarini replied on Mon, 2010/03/22 - 3:51pm

Nice !!!  Thanks for the info.  I was struggling with creating these key/value pairs in a .properties file in the /conf/props/ location in JBoss.  This is much cleaner and I can have environment specific files in the deploy folder.

 HG

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.