Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create global context variables in JBoss?

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.

like image 352
NobodyMan Avatar asked Nov 30 '25 04:11

NobodyMan


1 Answers

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.

like image 177
stacker Avatar answered Dec 02 '25 17:12

stacker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!