I like using JVM system properties as a way to access non hard coded resources. Typing System.getProperty("myPropertyName") is convenient and clean. The best part is that these properties have JVM scope, so you don't have to worry about class loaders.
For convenience let me define a couple of variables:
%JBOSS_HOME= directory where JBoss is installed
%JBOSS_SERVER= server instance name
There are 2 ways to define system properties in JBoss:
a) By specifying them in %JBOSS_HOME/bin/run.conf
You use run.conf, don't you? Don't change run.sh or run.bat directly. That makes your application less portable. The file run.conf is used by run.sh or run.bat to setup a number of properties. To setup system properties you need modify the JAVA_OPTS variable. Find this section in run.conf and modify it accordingly:
#
# Specify options to pass to the Java VM.
#
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms500m -Xmx500m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -DyourPropertyName=yourPropertyValue"
fi
As you can see I added the property yourPropertyName to the System Properties. So, once you restart the server, you will able to simply call System.getProperty("yourPropertyName") and get the value of it in any application running in JBoss.
The problem with this approach is that to change the values of the properties, or add values, you need to restart the server.
b) Use properties-service.xml
This is my favorite method. In $JBOSS_HOME/server/$JBOSS_SERVER/deploy you will find the file properties-service.xml . In this file you can specify new system properties, modify existing ones and even remove old ones. All you need to do is uncomment the following block in properties-service.xml:
<!--
| Set raw properties file style properties. -->
<attribute name="Properties">
yourPropertyName=yourPropertyValue
</attribute>
You don't need to restart the server for defined properties or changed in properties-service.xml to take effect. Placing properties with links to web services endpoints, LDAP servers and other resources in properties-service.xml makes an application EAR or WAR more portable and easier to move from a development environment to a production environment since the properties are outside of the deployment instruments.
Very useful article. Thank you!
Posted by: andrey | December 05, 2008 at 02:12 AM
I believe the run.conf file is not used by run.bat but only by run.sh. I personally had to edit run.bat file with ugly tweaks in order to set java system properties programatically. That is where your second option does a world of good!
Thanks for posting this info.
Posted by: Prem | December 14, 2008 at 01:07 AM
This article helped me. Thanks!
Posted by: Prakash | April 20, 2009 at 08:23 AM
Thanks a lot i knew there was some properties files someplace but could not find it in any of the off the shelf books.
Posted by: Prakash | October 20, 2009 at 10:55 AM
Thanks, just the info i was looking for!
Posted by: Karen | November 26, 2009 at 02:39 AM
Java programming language is a nice and cool programming language that I use whenever I make software for my clients. I think that because of its popularity it has some upgrades and its much nicer than before. Thanks for this great information, I could really use this someday.
Posted by: Association Management Software | June 09, 2010 at 12:30 AM
The world can be changed by man's endeavor, and that this endeavor can lead to something new and better .No man can sever the bonds that unite him to his society simply by averting his eyes . He must ever be receptive and sensitive to the new ; and have sufficient courage and skill to novel facts and to deal with them . (Franklin Roosevelt , American President )
Posted by: christian louboutin | November 04, 2010 at 01:57 AM
You are mighty.Nobody loves like you, Lord. You are a mighty God. You are mighty.
Posted by: Supra Shoes | November 08, 2010 at 12:36 AM
And remember Time is another river.
Posted by: Air Jordans | November 08, 2010 at 11:10 PM
Later road, we walk together.\
Posted by: Air Jordans | November 09, 2010 at 10:18 PM
i love you post
Posted by: taobao agent | November 10, 2010 at 10:45 PM
i love you posts
Posted by: taobao spree | November 11, 2010 at 01:32 AM
Good luck!
Posted by: taobao buy | November 11, 2010 at 11:00 PM
Tomorrow is an other day!@
Posted by: Air Jordan | November 13, 2010 at 12:05 AM
*Later road, we walk together.*_*
Posted by: air jordan | November 15, 2010 at 06:15 PM
I also like using JVM system properties. It seems for me to be the best way. Thanks for the great post
Posted by: casino online | November 16, 2010 at 03:40 AM
I can imagine TONS of uses for this*_*
Posted by: air jordan | November 16, 2010 at 06:36 PM
I just wish I knew what to do.*
Posted by: Air Jordan | November 16, 2010 at 06:55 PM
hai.I like this site. Very practical and very motivational. Thanks a bunch. This will help me a lot.
Posted by: link building service | November 23, 2010 at 02:56 AM
Cela a été amusant, j'ai apprécié la lecture de votre blogfest entrée! J'aime de boules de neige - même si je n'ai jamais eu à jouer contre des gens avec des cadeaux! LOL. Je suis d'accord. Les gens ont besoin pour égayer de leur nouvelle pièce grande de l'art. : D
Posted by: jordan 11 space jam | December 20, 2010 at 12:18 AM
J'ai entendu cette chanson à la radio de voiture ce matin. Je continue à penser sur les deux premières lignes - se demandant s'il existe des preuves que je suis une femme défectueux. Quand je vois un cerf, je pense ragoût de chevreuil bourgogne - mais je suis heureux, je ne suis pas celui qui devait tirer sur le pauvre.
Posted by: Air Jordan Retro | December 31, 2010 at 12:23 AM
I wandered lonely as a cloud !
Posted by: retro air jordans | January 04, 2011 at 07:53 PM
Fortune never helps the man whose courage fails.
Posted by: Coach Outlet | January 04, 2011 at 09:51 PM
No man or woman is worth your tears, and the one who is, won't make you cry. O(∩_∩)O~
Posted by: UGG Joslyn Boots | January 05, 2011 at 10:29 PM
I had a dream to begin my business, nevertheless I did not earn enough amount of money to do that. Thank goodness my close friend said to take the loans. So I took the credit loan and realized my desire.
Posted by: AntoniaBooker20 | January 28, 2011 at 05:58 AM