Java – How to create global context variables in JBoss

jakarta-eejavajbossjboss-4.2.x

This is a follow-up to a question I posted a while back: "Can I use a single WAR in multiple environments?". I was able to create a single-war solution in Tomcat, but now we are migrating our app to JBoss 4.2 and I can't figure out how to set up global environment variables.

In Tomcat 6 this was pretty straightforward: I simply put the following snippet in tomcat/conf/Catalina/myappname.xml:

<Context ...>
   <Environment name="TARGET_ENV" value="DEV" type="java.lang.String" override="false"/>
</Context>

Then in my app I was able to resolve the environment name with the following:

Context context = (Context) InitialContext().lookup("java:comp/env");
String targetEnvironment = (String) context.lookup("TARGET_ENV");

The problem is that I can't find out where/how to place global variables in JBoss. I've tried putting the <Environment> tag in the following files to no avail:

  • server/all/deploy/jboss-web.deployer/context.xml
  • server/default/deploy/jboss-web.deployer/context.xml

I know that I can put environment variables in my app's web.xml but that defeats the purpose of having a unified war – I'd still need custom .war's for dev, qa and prod.

I'm a JBoss newbie so if there's any additional information that would help just let me know and I'll append to this question.

Best Answer

I use somehing similar to PropertiesService for database url, and other environment related things.

Therefore I'm relieved from the burden to provide different environment related atrifacts.