How can I create global context variables in JBOSS?

Posted by NobodyMan on Stack Overflow See other posts from Stack Overflow or by NobodyMan
Published on 2010-06-09T18:27:45Z Indexed on 2010/06/09 18:32 UTC
Read the original article Hit count: 238

Filed under:
|
|

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. Many thanks! --N

© Stack Overflow or respective owner

Related posts about java

Related posts about j2ee